Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome runs tests twice in karma

When using Chrome in my karma tests, I often (more than 50% of all runs) see that each test is executed twice by Chrome. Below you can find an example output and my configuration.

How can I stop this? What is the cause?

karma start --single-run --browsers Firefox,Chrome

INFO [karma]: Karma v0.12.17 server started at http://localhost:9876/
INFO [launcher]: Starting browser Firefox
INFO [launcher]: Starting browser Chrome

INFO [Chrome 36.0.1985 (Linux)]: Connected on socket RV8G8p63bCLQGaAJW9Hc with id 91444447
Chrome 36.0.1985 (Linux): Executed 0 of 92 SUCCESS (0 secs / 0 secs)
Chrome 36.0.1985 (Linux): Executed 1 of 92 SUCCESS (0 secs / 0.065 secs)
[...]
Chrome 36.0.1985 (Linux): Executed 91 of 92 SUCCESS (0 secs / 0.24 secs)
Chrome 36.0.1985 (Linux): Executed 92 of 92 SUCCESS (0 secs / 0.241 secs)
Chrome 36.0.1985 (Linux): Executed 92 of 92 SUCCESS (0.274 secs / 0.241 secs)
Chrome 36.0.1985 (Linux): Executed 93 of 92 SUCCESS (0.274 secs / 0.258 secs)
[...]
Chrome 36.0.1985 (Linux): Executed 183 of 92 SUCCESS (0.274 secs / 0.412 secs)
Chrome 36.0.1985 (Linux): Executed 184 of 92 SUCCESS (0.274 secs / 0.413 secs)

INFO [Iceweasel 30.0.0 (Linux)]: Connected on socket 4DISHs7012QeIwhEW9Hd with id 93232241

Chrome 36.0.1985 (Linux): Executed 184 of 92 SUCCESS (0.274 secs / 0.413 secs)
Iceweasel 30.0.0 (Linux): Executed 0 of 92 SUCCESS (0 secs / 0 secs)
Chrome 36.0.1985 (Linux): Executed 184 of 92 SUCCESS (0.274 secs / 0.413 secs)
Iceweasel 30.0.0 (Linux): Executed 1 of 92 SUCCESS (0 secs / 0.003 secs)
[...]
Iceweasel 30.0.0 (Linux): Executed 91 of 92 SUCCESS (0 secs / 0.201 secs)
Chrome 36.0.1985 (Linux): Executed 184 of 92 SUCCESS (0.274 secs / 0.413 secs)
Iceweasel 30.0.0 (Linux): Executed 92 of 92 SUCCESS (0 secs / 0.202 secs)
Chrome 36.0.1985 (Linux): Executed 184 of 92 SUCCESS (0.274 secs / 0.413 secs)
Iceweasel 30.0.0 (Linux): Executed 92 of 92 SUCCESS (0.303 secs / 0.202 secs)
TOTAL: 276 SUCCESS

Configuration:

module.exports = function(config) {
  config.set({

    basePath : 'www',

    frameworks : [ 'jasmine' ],

    files : [ 'js/*' ],

    exclude : [ 'spec/lib/*.js' ],

    reporters : [ 'progress', 'junit', 'html', 'coverage' ],

    coverageReporter : {
      type : 'html',
      dir : 'coverage/'
    },

    preprocessors : {
      'js/*.js' : 'coverage',
    },

    junitReporter : {
      outputFile : 'test-results.xml'
    },

    colors : true,

    logLevel : config.LOG_INFO,

    autoWatch : true,

    browsers : [ 'Firefox', 'Chrome' ],

    captureTimeout : 20000,

    reportSlowerThan : 500,

    plugins : [ 'karma-jasmine', 'karma-coverage', 'karma-html-reporter', 'karma-chrome-launcher', 'karma-junit-reporter', 'karma-phantomjs-launcher', 'karma-firefox-launcher' ]

  });
};
like image 282
C-Otto Avatar asked Jul 17 '14 12:07

C-Otto


1 Answers

You might have your karma config wrong. It should know where your test files are but not include them:

files : ['js/*']

might need to change to:

files : ['js/*.js',
         { pattern: 'tests/*.js', included: false }]

(This expects your source files to be under ./js/ and your tests to be under ./tests/

(I got this from [https://medium.com/@SchizoDuckie/so-your-karma-tests-run-twice-this-is-what-you-need-to-do-be74ce9f257e#.m3ci0m5vb] and it worked for me)

like image 60
SHug Avatar answered Sep 18 '22 17:09

SHug