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?
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);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With