Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Karma exits with code 1 when it doesnt execute any spec tests

Karma test runs fine but exits with code 1 if 0 of 0 tests are run. Does anyone know how to return exit code 0 and normally exit in this case? Using gulp-karma which fails the task when no specs are run.

like image 832
Encore PTL Avatar asked Feb 05 '15 15:02

Encore PTL


2 Answers

There is a configuration option that allows for empty test suites. Just add

failOnEmptyTestSuite: false

to your karma.conf.js and the process will exit with exit code 0.

BR Chris

like image 109
cschuff Avatar answered Oct 17 '22 19:10

cschuff


In your gulpfile, replace the "throw err" on the error callback in the your gulp test task with "this.emit('end')".

gulp.task('test', function() {
  return gulp.src(testFiles)
    .pipe(karma({
      configFile: 'karma.conf.js',
      action: 'run'
  }))
  .on('error', function(err) {
    throw err;
  });
});

so your test task now looks like;

gulp.task('test', function() {
  return gulp.src(testFiles)
    .pipe(karma({
      configFile: 'karma.conf.js',
      action: 'run'
  }))
  .on('error', function(err) {
   this.emit('end');
  });
});
like image 44
Olatunde Garuba Avatar answered Oct 17 '22 17:10

Olatunde Garuba