gulpgulp-karma

How to run second task only when karma test task is successful with Gulp?


I am using Gulp. I have a deploy task that runs after test task. The problem is that deploy task runs even if test failed. Is there a way to run deploy task only when tests are successful in gulp?

gulp.task('test', function() {
  return gulp.src('some_test_tile')
    .pipe(karma({
      configFile: 'karma.conf.js',
      action: 'run'
    }));
});

gulp.task('deploy', ['test'], function() {
  return gulp.src(paths.scripts)
    .pipe(gulp.dest(paths.dest));
});

I am using gulp-karma to run Karma tests.


Solution

  • The gulp-karma example says to add .on('error', ...) after the pipe to karma, and manually throw the error to ensure gulp exits non-zero if any tests fail. That should do it.