Gulp 4 中的错误处理

10

我试图编写一个简单的 watch 任务,用于监视我的测试文件,一旦发生更改,就会使用 gulp-jasmine 编译并运行它们。

我的 watch 任务:

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

以及测试任务:

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

但是,如果测试代码包含错误,例如is not a function或其他任何错误,监视任务将崩溃,我不得不一遍又一遍地重新启动它。我的错误处理程序甚至没有被调用。那么我该如何正确处理错误?

1个回答

2
尝试使用以下方法来处理错误:
 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);
    });

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接