5

我在尝试设置 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

我会很感激任何帮助!

4

1 回答 1

1

萨尔瓦多,

嘿。我发现问题出在 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.

此外,我确实更新了 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>
于 2013-06-25T22:40:25.273 回答