10

I'm trying to write simple watch task that will watch my tests files and on change compile them and run using gulp-jasmine.

My watch task:

gulp.task('watch', function () {
    gulp.watch(['tests/**/[^_]*.ts'], gulp.series(['compile_tests', 'test']));
})

and the test task:

gulp.task('test', function(){
    return gulp.src('tests/**/[^_]*.spec.js')
        .pipe(
            jasmine().on('error', function(error){
                console.log(error);
                this.emit('end');
            })
        );
});

But if tested code contain errors, like is not a function or whatever, watch task crashes and I have to restart it again and again. My error handler not even being called. So how can I handle errors in proper way?

SET001
  • 11,480
  • 6
  • 52
  • 76

1 Answers1

2

Try this way to handle error

 gulp.task('test', function(){
        var j = jasmine({});
        j.on('error',function(e){
            console.log(e);
            j.end();
      });
      return gulp.src('tests/**/[^_]*.spec.js')
          .pipe(j);
    });
Sreeragh A R
  • 2,871
  • 3
  • 27
  • 54