2013-04-03 64 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>