2013-04-03 65 views
5

我試圖設置PhantomJS時遇到了問題,所以我可以通過Travis CI對我的JavaScript項目進行持續集成。QUnit + PhantomJS:asyncTest永不返回

基本上,即使是最簡單的asyncTest只是永遠不會返回。如果使用node進行測試,或者在瀏覽器中使用,例如Chrome,它就可以正常工作。

asyncTest看起來像這樣:

asyncTest ("async test", function() { 
    expect(1); 
    console.log("Beginning test..."); 
    setTimeout(function() { 
     ok(true, "true is true"); 
     start(); 
     console.log("Test should now end..."); 
    }, 200); 
}); 

我已經建立了一個資料庫與最少的代碼來重現問題:

https://github.com/siovene/phantomjs-async-test

我會很感激任何幫助!

+0

如果您使用另一個異步方法比'setTimeout',它工作嗎?就像回調函數一樣簡單? – Odi

+0

不,同樣的問題。最初,我在我的代碼中發現了使用回調函數的問題,但是我使用'setTimeout'做了一個最小例子。 –

回答

1

Salvatore,

嘿。我發現問題在qunit-logging.js中。當我從index.html中刪除它時,測試運行良好。

這裏就是我所做的運行phantomjs內qunit。\

C:\ TEMP \ qunit_test> C:\幻象\ phantomjs.exe runner.js文件:/// C:/溫度/ qunit_test /索引。 html

Results: 
Beginning test... 
Test should now end... 
Took 2045ms to run 1 tests. 1 passed, 0 failed. 

此外,我沒有更新從cdn運行qunit源。我無法確定您使用的是哪個版本(從2012年開始我就可以告訴),並且我想用最新版本進行故障排除。所以這裏是我的index.html文件:

<!DOCTYPE html> 
<html> 
    <head> 
     <meta charset="UTF-8"> 
     <title>Test Suite</title> 

     <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> 

    </head> 
    <body> 
     <div id="qunit"></div> 
     <div id="qunit-fixture"></div> 

      <!-- qunit --> 
     <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.12.0.css" type="text/css" media="screen" /> 
     <script src="http://code.jquery.com/qunit/qunit-1.12.0.js"></script> 
     <!--<script src="qunit-logging.js"></script>--> 

     <script type='text/javascript'> 
      module("lib-test"); 

      asyncTest ("async test", function() { 
       expect(1); 
       console.log("Beginning test..."); 
       setTimeout(function() {   
        start(); 
        ok(true, "true is true"); 
        console.log("Test should now end..."); 
       }, 2000); 
      });  

     </script> 

    </body> 
</html>