var jasmine = require('gulp-jasmine');
var debug = require('gulp-debug');
var testFunc = function(platform, testType) {
var timer = startTimer();
console.log('started!');
return gulp.src('./src/**/_test/**/*.mem.js')
.pipe(jasmine({
verbose: !!args.verbose,
timeout: 15000
}))
.pipe(debug())
.on('error', function(e) {
console.log('started!');
throw e;
})
.on('end', function() {
console.log('end!');
console.log(stopTimer(timer));
});
};
gulp.task('mem', function(done) {
testFunc('chrome', 'mem').on('end', function() {
console.log('done!');
done();
});
});
关于gulp v3.9.1。上面的代码完成后没有记录“结束!”或“完成!”到控制台。我该怎么做才能实现这一目标?
My console output:
> gulp mem
[13:10:39] Using gulpfile ~/foo/bar/gulpfile.js
[13:10:39] Starting 'mem'...
started!
[13:10:39] gulp-debug: src/components/avatar/_test/avatar.mem.js
[13:10:39] gulp-debug: src/factories/store/_test/store.mem.js
[13:10:39] gulp-debug: 2 items
更新
下面提到了Lentus的建议,它适用于同步任务,例如gulp-debug。但是像gulp-jasmine这样的异步,流在该任务完成之前结束。您还会注意到“X秒后完成'mem'不会打印出来:
My console output:
> gulp mem
[13:10:39] Using gulpfile ~/foo/bar/gulpfile.js
[13:10:39] Starting 'mem'...
started!
ended!
...
3 specs, 0 failures
Finished in 18.5 seconds
答案 0 :(得分:0)
当你想让gulp异步做事时gulp会提供一个回调来让它知道任务完成的时间。例如:
gulp.task('build', function(taskFinishedCb) {
gulp.src("SOURCE_FILE_PATH/GLOB")
.on('error', function(e) {
console.log('started!');
throw e;
})
.on('end', function() {
console.log('end!');
console.log(stopTimer(timer));
})
.pipe(jasmine({
verbose: !!args.verbose,
timeout: 15000,
// This is the big thing you need according to the Jasmine docs
// This specifies a callback to invoke when the tests are done
onComplete: taskFinishedCb
}))
.pipe(debug())
});
我在Jasmine中看到了onComplete选项的问题,所以它可能无法按预期工作,但理论上它是如何完成的。让我知道它是怎么回事