Karma closing browsers after gulp test

4.5k views Asked by At

I'm running basic jasmine tests using the Chrome and Firefox launchers in karma, from gulp. But my browsers are always being closed afterwards. Regardless of success or failure in tests, even after specifying single run as false in the task and the config.

Gulp task:

 karma = require('gulp-karma');



gulp.task('test', ['testsSetup'], function() {
  // Be sure to return the stream
  // NOTE: Using the fake './foobar' so as to run the files
  // listed in karma.conf.js INSTEAD of what was passed to
  // gulp.src !
 return gulp.src('./foobar')
  .pipe(karma({
   configFile: 'karma.conf.js',
   singleRun: false
}))
    .on('error', function(err) {
      // Make sure failed tests cause gulp to exit non-zero
      console.log(err);
      //this.emit('end'); //instead of erroring the stream, end it
    });
});

karma.conf.js:

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome','Firefox'],


// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false

Last part of the gulp output from successful tests:

Chrome 43.0.2357 (Windows 7 0.0.0): Executed 3 of 3 SUCCESS (0.041 secs / 0.036 secs)

Firefox 38.0.0 (Windows 7 0.0.0): Executed 3 of 3 SUCCESS (0.001 secs / 0.013 secs)

TOTAL: 6 SUCCESS

Chrome 43.0.2357 (Windows 7 0.0.0): Executed 3 of 3 SUCCESS (0.041 secs / 0.036 secs)

Firefox 38.0.0 (Windows 7 0.0.0): Executed 3 of 3 SUCCESS (0.001 secs / 0.013 secs)

TOTAL: 6 SUCCESS

[11:09:27] Finished 'test' after 4.52 s

Process terminated with code 0.

1

There are 1 answers

1
ChrisFletcher On BEST ANSWER

When you use gulp-karma the arguments you pass in are different to the arguments you'd pass straight to karma. The above singleRun parameter is ignored. I changed my task to the following (specifying an action instead) and it works as you'd expect:

gulp.task('test', ['testsSetup'], function() {
  // Be sure to return the stream
  // NOTE: Using the fake './foobar' so as to run the files
  // listed in karma.conf.js INSTEAD of what was passed to
  // gulp.src !
  return gulp.src('./foobar')
    .pipe(karma({
      configFile: 'karma.conf.js',
      action: 'watch',
      showStack: true
    }))
    .on('error', function(err) {
      // Make sure failed tests cause gulp to exit non-zero
      console.log(err);
      this.emit('end'); //instead of erroring the stream, end it
    });
});