Error handling in gulp 4

I am trying to write a simple viewing task that will keep track of my test files, and when compiling their changes and run using gulp-jasmine .

My task:

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

and 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 the verified code contains errors such as is not a function or something else, watch for the failures of the task, and I have to restart it again and again. My error handler is not even called. So how can I handle errors correctly?

+7
gulp gulp-watch
source share
1 answer

Try this method to handle the 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); }); 
0
source share

All Articles