QUnit + PhantomJS:asyncTest永远不会返回

Sal*_*ene 5 qunit phantomjs

我在尝试设置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);
});
Run Code Online (Sandbox Code Playgroud)

我已经用最小的代码建立了一个存储库来重现问题:

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

我很感激任何帮助!

Per*_*Tew 1

萨尔瓦多,

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

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

C:\temp\qunit_test>c:\phantom\phantomjs.exe runner.js 文件:///c:/temp/qunit_test/index.html

Results:
Beginning test...
Test should now end...
Took 2045ms to run 1 tests. 1 passed, 0 failed.
Run Code Online (Sandbox Code Playgroud)

另外,我确实更新了 qunit 源以从 CDN 运行。我不知道你使用的是哪个版本(我只能说是 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>
Run Code Online (Sandbox Code Playgroud)