karma-runnerkarma-jasminegulp-karma

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.


Solution

  • 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');
      });
    });