Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error handling in gulp 4

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?

like image 917
SET Avatar asked May 22 '16 22:05

SET


1 Answers

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);
    });
like image 172
Sreeragh A R Avatar answered Oct 18 '22 16:10

Sreeragh A R