2016-06-10 57 views
0
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(); 
    }); 
}); 

On gulp v3.9.1。上面的代码完成后没有记录“结束!”或“完成!”到控制台。我该怎么做才能做到这一点?吞吐任务在Stream发出“结束”事件之前退出

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 

UPDATE:

注意到下面迟缓芽孢杆菌的建议,这对于同步任务运作良好,像一饮而尽调试。但是异步的,比如吞噬茉莉花,流在任务完成之前结束。您还会注意到,“完成‘MEM’X秒后”不打印:

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

在对数据做任何事情之前设置事件。你尝试过吗? – KreemPuff

+0

嗯,这样的工作......我很好奇,为什么我看到的每个例子吞噬事件处理程序添加在管道列表的最后,而不是开始? – AlexZ

+0

它们可能是更长时间运行任务的示例。但通常情况下,您希望尽可能早地设置侦听器 – KreemPuff

回答

0

Gulp Doc Async Tasks

当你想吞掉做的事情异步一饮而尽提供回调让它知道什么时候任务完成。例如:

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选项的问题,所以它可能无法按预期工作,但这是理论上的方式。让我知道它是怎么回事

+0

刚刚尝试过 - 可悲的是,结果和以前一样:/感谢您的建议,但!有趣的是,当我使用“return gulp.src(”blah“)...”它工作正常,但是当我尝试使用“完成”回调或返回一个Promise时,'end'事件被触发订单/根本没有。 – AlexZ

+0

有趣的,猜测我保存这个问题以后的大声笑。和NP – KreemPuff

+0

哦,看,还有的是有这样的问题:) https://github.com/sindresorhus/gulp-jasmine/issues/49貌似这个问题的人一整群主要是一饮而尽,茉莉特定(或者说,如何我正在使用它)。正如讨论中所建议的那样,我想我必须使用gulp-exit。 – AlexZ

相关问题