karma error 'There is no timestamp for'

Viewed 39224

Trying to get karma working with requirejs. I don't understand why I am getting all of these errors when running Karma:

ERROR: 'There is no timestamp for /base/test/mainSpec.js?bust=1387739317116!'
ERROR: 'There is no timestamp for /base/app/main.js?bust=1387739317116!'
ERROR: 'There is no timestamp for /base/bower_components/jquery/jquery.js?bust=1387739317116!'

When I go to the network tab in inspector, all of the files are there with no 404s.

I'm a little confused because karma seems to be looking for a 'base' directory but there is no 'base' directory in my project. According to the karma docs:

Karma serves files under the /base directory. So, on the server requests to files will be served up under http://localhost:9876/base/*. The Require.js config for baseUrl gives a starting context for modules that load with relative paths. When setting this value for the Karma server it will need to start with /base. We want the baseUrl for our tests to be the same folder as the base url we have in src/main.js, so that relative requires in the source won’t need to change. So, as we want our base url to be at src/, we need to write /base/src.

This confusing to say the least. Am I supposed to have a baseUrl configuration in my main.js file that points to '/base'?

9 Answers

Expanding from @Naruto Sempai's answer:

I resolved this issue by first setting the basePath attribute in my karma.conf.js file. This path contains the needed ../ (previous directory) strings until my path was at the root of my source/test files.

Then I modified my test-main.js file (containing my RequireJS configuration) and set the baseUrl to /base.

Now, no timestamp errors.

--

To illustrate my environment and paths I configured, heres a basic setup example:

Source file location:
/Users/ben/some-project/src/main/resources/var/www/project/js/app

Test file location:
/Users/ben/some-project/src/test/var/www/project/

Karma Config location:
/Users/ben/some-project/src/test/var/www/project/karma.conf.js

Test RequireJS Config location:
/Users/ben/some-project/src/test/var/www/project/test-main.js

My karma.conf.js:

module.exports = function (config) {
    config.set({
       basePath: '../../../../' 
    });
}

to make my "root" at /Users/ben/some-project/src/.

My test-main.js:

requirejs.config({
   baseUrl: '/base' 
});
Related