gpt4 book ai didi

gulp - gulp 4 中的错误处理

转载 作者:行者123 更新时间:2023-12-04 08:51:28 25 4
gpt4 key购买 nike

我正在尝试编写简单的监视任务,该任务将监视我的测试文件并在更改时编译它们并使用 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或者无论如何,观看任务崩溃,我必须一次又一次地重新启动它。我的错误处理程序甚至没有被调用。那么如何以正确的方式处理错误呢?

最佳答案

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);
});

关于gulp - gulp 4 中的错误处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37380140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com