QUnit + PhantomJS:asyncTest永远不会返回

时间:2013-04-03 16:01:56

标签: phantomjs qunit

我在尝试设置PhantomJS时遇到了问题,所以我可以通过Travis CI对我的JavaScript项目进行持续集成。

基本上,即使是最简单的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

我很感激任何帮助!

1 个答案:

答案 0 :(得分:1)

的Salvatore,

嘿。我发现问题出在qunit-logging.js中。当我从index.html中删除它时,测试运行正常。

这是我在phantomjs中运行qunit所做的工作。\

C:\ temp \ qunit_test> c:\ phantom \ phantomjs.exe runner.js file:/// c:/temp/qunit_test/index.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>
相关问题