9

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.

Encore PTL
  • 7,144
  • 8
  • 35
  • 72

2 Answers2

31

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

cschuff
  • 5,192
  • 3
  • 31
  • 51
  • 3
    This is the real answer to the question as asked. – Zhuge Nov 20 '17 at 22:50
  • This solves the question! But note, it still does output "0 of 0 ERROR" to the console in red coloring, which can be visually misleading. – trusktr Oct 02 '20 at 23:12
1

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');
  });
});
Olatunde Garuba
  • 979
  • 1
  • 15
  • 21