只寫一個(到目前爲止)非常簡單的gulp文件,我感到困惑的錯誤,我遇到過。爲什麼將`done`函數傳遞給Karma的服務器時出現錯誤?
當測試失敗,此任務,一飲而盡正常退出
gulp.task('test', done => {
new KarmaServer({
configFile: __dirname + '/karma.conf.js',
singleRun: true
},() => done()).start();
});
...生產:
Chrome 50.0.2661 (Mac OS X 10.11.3): Executed 11 of 11 (3 FAILED) (0.053 secs/0.023 secs)
[17:38:02] Finished 'test' after 2.43 s
但是當你苗條下來,只是通過done
到噶,它失敗而無禮地
...產生:
Chrome 50.0.2661 (Mac OS X 10.11.3): Executed 11 of 11 (3 FAILED) (0.066 secs/0.042 secs)
[17:36:39] 'test' errored after 2.45 s
[17:36:39] Error: 1
at formatError (/usr/local/lib/node_modules/gulp/bin/gulp.js:169:10)
at Gulp.<anonymous> (/usr/local/lib/node_modules/gulp/bin/gulp.js:195:15)
at emitOne (events.js:77:13)
at Gulp.emit (events.js:169:7)
at Gulp.Orchestrator._emitTaskDone (/Users/markstickley/workspace/timewarp/node_modules/gulp/node_modules/orchestrator/index.js:264:8)
at /Users/markstickley/workspace/timewarp/node_modules/gulp/node_modules/orchestrator/index.js:275:23
at finish (/Users/markstickley/workspace/timewarp/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:21:8)
at cb (/Users/markstickley/workspace/timewarp/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:29:3)
at removeAllListeners (/Users/markstickley/workspace/timewarp/node_modules/karma/lib/server.js:336:7)
at Server.<anonymous> (/Users/markstickley/workspace/timewarp/node_modules/karma/lib/server.js:347:9)
at Server.g (events.js:260:16)
at emitNone (events.js:72:20)
at Server.emit (events.js:166:7)
at emitCloseNT (net.js:1518:8)
at doNTCallback1 (node.js:418:9)
at process._tickCallback (node.js:340:17)
誰能解釋爲什麼出現這種情況,因爲done
是一個功能和done
所有包裹版本所做的就是調用done
?
嗨Wilmer,非常感謝你的詳細解答。不過,我恐怕不管我是否誤解了你的答案,或者你誤解了這個問題。特別是,我認爲可能會對使用es6箭頭函數對'done'做出錯誤的解釋。 https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions當我回到我的電腦時,我可以發佈一個沒有箭頭功能的es5版本,這些功能展示了完全相同的特性 - 我只能想象它是一些範圍問題,我還沒有明白... –
在es5中: gulp.task('test',function(done){ new KarmaServer({config | config_file:__dirname +'' /karma.conf.js', singleRun:true },function(){done();})。start(); }); 與 gulp.task( '測試',函數(完成){ 新KarmaServer({ CONFIGFILE:__dirname + '/karma.conf.js', singleRun:真 },完成)。開始( ); }); –
@MarkStickley我作爲編輯添加了答案,因爲它太長了。 –