2016-06-10 58 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

相關問題