[英]POST call from phantomJS doesn't hit server running from grunt
這是我的設置。
test-index.html
頁面上運行測試。 test-index.html
頁在我啟動服務器的端口上發送POST調用。 問題:POST呼叫沒有打到我的服務器。
注意:如果我手動運行同一服務器(而不是從grunt運行),然后運行test grunt任務,則POST調用會命中該服務器。
這是代碼:
艱巨的任務
grunt.registerMultiTask('coverage', 'Generates coverage reports for JS using Istanbul', function () {
var server = http.createServer(function(req, resp) {
resp.setHeader("Access-Control-Allow-Origin", "*");
console.log('Got something');
req.pipe(fs.createWriteStream('coverage.json'))
resp.end();
});
var port = 7358;
server.listen(port);
// This task simply executes a command: `testem.js ci`
grunt.task.run('testem').then(function() {
server.close();
});
});
test-index.html(位於中的某處)
function onTestemLoad() {
Testem.on('all-test-results', function(results){
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://localhost:7358/');
xhr.send(JSON.stringify(window.__coverage__))
});
}
誰能指出這里可能出了什么問題?
您被grunt.task.run
! 該行不會運行任務,只是將其放在當前任務完成后要運行的任務列表的頂部( http://gruntjs.com/api/grunt.task#grunt.task.run )。
第二個問題是,任務完成后,它會帶走所有正在運行的進程。
所以發生的是:
coverage
開始,在服務器上旋轉,然后將testem
注冊為下一個任務 coverage
結束,關閉服務器 testem
)運行,但是這里沒有服務器可以回答... 您可以通過執行以下兩項操作來修復它:
grunt.task.run('testem')
this.async
請參見http://gruntjs.com/api/inside-tasks#this.async )。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.