Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QUnit + PhantomJS: asyncTest never returns

I've run into a problem when trying to setup PhantomJS, so I could do continuous integration on my JavaScript project via Travis CI.

Basically, even the simplest asyncTest just never returns. It works fine when tested with node or in a browser, like Chrome.

My asyncTest looks like this:

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);
});

I've set up a repository with the minimal code to reproduce the problem:

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

I'd appreciate any help!

like image 259
Salvatore Iovene Avatar asked Nov 13 '22 08:11

Salvatore Iovene


1 Answers

Salvatore,

Hey. I found the problem to be within the qunit-logging.js. When I removed that from your index.html, the tests ran fine.

Here's what I did to run the qunit within phantomjs.\

  • I commented out the qunit-logging.js reference.
  • I downloaded the runner.js plugin from the qunit tree: https://github.com/jquery/qunit/tree/master/addons/phantomjs
  • I put that in the same directory as your main files (in my case, it was c:\temp\qunit_test).
  • I then ran this from my command line:

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.

Also, I did update the qunit sources to run from the cdn. I couldn't tell what version you were using (it's from 2012 is all I could tell), and I wanted to troubleshoot with the latest version. So here's my index.html file:

<!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>
like image 93
Perry Tew Avatar answered Dec 15 '22 07:12

Perry Tew