为什么gulp命令需要运行两次才能让构建通过?

时间:2016-11-17 12:53:10

标签: gulp

gulpfile.js

gulp

当我在其中一个测试中创建拼写错误时,期望运行[13:46:35] Using gulpfile ~/path/to/gulpfile.js [13:46:35] Starting 'compile'... [13:46:35] Starting 'test'... .... 4 specs, 0 failures Finished in 0 seconds [13:46:35] Finished 'test' after 35 ms [13:46:35] Compiling TypeScript files using tsc version 2.0.6 [13:46:37] Finished 'compile' after 1.86 s [13:46:37] Starting 'default'... [13:46:37] Finished 'default' after 14 μs 会抛出错误,但它会通过:

gulp

[13:46:39] Using gulpfile ~/path/to/gulpfile.js [13:46:39] Starting 'compile'... [13:46:39] Starting 'test'... ...F Failures: 1) Calculator 8 multiplied by 2 should be 16 1.1) Expected 10 to equal 16. 1.2) Expected 6 to equal 9. 1.3) Expected 10 to equal 24. 4 specs, 1 failure Finished in 0 seconds [13:46:39] 'test' errored after 36 ms [13:46:39] Error in plugin 'gulp-jasmine' Message: Tests failed [13:46:39] Compiling TypeScript files using tsc version 2.0.6 [13:46:41] Finished 'compile' after 1.93 s 需要运行两次才能让构建失败:

gulp.task('compile', function(cb) {
    gulp.src(['typings/index.d.ts', 'src/*.ts', 'spec/*.ts'])
        .pipe(typescript()).pipe(gulp.dest('dist/js/'))
    cb();
});

gulp.task('test', ['compile'], function() {
    return gulp.src('dist/js/spec/test.js')
        .pipe(jasmine());
});

//http://stackoverflow.com/a/26390567/2777965
gulp.task('default', ['compile', 'test']);

尝试2

compile step

预期结果

期望是如果第一次运行拼写错误并且gulp运行,则构建将失败。

讨论

为什么我需要在这种情况下运行Gulp两次?输出表明在运行测试代码之前执行了{{1}}。

0 个答案:

没有答案