Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

karma error 'There is no timestamp for'

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'?

like image 841
Jeff Avatar asked Dec 22 '13 19:12

Jeff


4 Answers

note: This post was valid by Karma in 2014 Jan 16. I am not certain of the current state of that lib, maybe they fixed their weird configuration logic and added meaningful error messages. If not, then this post can be probably very helpful by fixing configuration issues related to Karma.

These kind of errors occur by misconfiguration. You should add everything your test uses to the file patterns in your config file.

For example:

module.exports = function (config) {
    config.set({
        basePath: './',
        frameworks: ['jasmine', 'requirejs'],
        files: [
            {pattern: 'test/bootstrap.js', included: true},
            {pattern: 'test/**/*.js', included: false},
            {pattern: 'src/**/*.js', included: false},
            {pattern: 'vendor/**/*.js', included: false}
        ],
        exclude: [

        ],
        reporters: ['progress'],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browsers: ['Firefox'],
        captureTimeout: 6000,
        singleRun: false
    });
};

In this example the bootstrap.js is the only file included by Karma in the HTML, the other files are dependencies which are loaded by the code in the bootstrap.js. The pattern order is very important and sadly it is far from logical: the next pattern does not override the previous one. So if I'd give the test/**/*.js pattern as first and test/bootstrap.js as second, it would not work because the bootstrap would not be included. In these cases Karma sends you an "empty testsuite" message, which is useless if you don't know how to configure it...

If your tests try to use a file which is not covered by the patterns you gave in your Karma configuration file, then you will get the "There is no timestamp for xy" error message, which is very similar to the previously mentioned "empty testsuite". If you don't know the system you won't have a clue, what it means, or what you have to do in order to fix it ...

The exclude part of the configuration object is for files, which have been added to the file patterns for inclusion, but you don't want to include or use them in your tests. These can be for example requirejs configuration files for development and production environments, etc...

like image 88
inf3rno Avatar answered Nov 19 '22 02:11

inf3rno


For me it was simply making the mistake of setting basePath: 'base' instead of baseUrl: '/base'.

baseUrl: '/base' ftw!

like image 34
Naruto Sempai Avatar answered Nov 19 '22 02:11

Naruto Sempai


The basePath is to identify the root of your project relative to the configuration file (karma.conf.js). Take a look at this example: https://github.com/karma-runner/karma/blob/v0.8.5/test/client/karma.conf.js

In the browser, I also got this error about the timestamp but it doesn't affect anything. The tests are working properly. I guess it should be a warning more than an error :-)

like image 4
Jeff Renaud Avatar answered Nov 19 '22 02:11

Jeff Renaud


Jeff's right, you should exclude the requirejs config file of your app, because "we don't want to actually start the application in our tests. [LINK]".

The test-main.js config file is a separate file from the requirejs config file your app uses, which in your case might be config.js or main.js, depending on where you config your requirejs.

They both configures path and dependencies (could be specifying about the same ones), but the former is to provide requirejs support for the tests you write. This whole requirejs setup is a separate one from the requirejs you use in your app. So don't include the latter, it confuses Karma.

And the link above is a working Karma with its requirejs demo, check it out.

like image 3
Lucia Avatar answered Nov 19 '22 03:11

Lucia