3

After much searching and quite a bit of trial it seems to me that the chosen combination of tools just doesn't have it. I would LOVE to be mistaken.

Well, the technological stack is as mentioned in the title. To expand,

  1. Backbone for all "classes"
  2. RequireJS to load and manage dependencies between Backbone entities
  3. QUnit (where tests are also RequireJS modules)
  4. JsTestDriver for command line automation

Setup and code snippets

jsTestDriver.conf

server: http://localhost:48080
basepath: path/to/JSTestDriver/
load:
  - lib/qunit/qunit-1.10.0.js
  - lib/qunit/equiv.js
  - lib/qunit/QUnitAdapter.js
  - lib/requirejs/require.js
test:
  - test/tests.js
serve:
  - lib/jquery/jquery-1.7.1.js
  - test/components/ComponentOneTest.js

tests.js

require({  
    baseUrl : '/test',
    shim : {
        'fixture.object' : ['jquery'],
        'fixture.string' : ['jquery'],
        'fixture.dom' : ['jquery', 'fixture.string'],
        'fixtures' : ['fixture.object', 'fixture.string', 'fixture.dom'],
        'equiv' : ['qunit'],
        'qunit.adapter' : ['qunit', 'equiv']
    },
    paths: {  
        'text' : 'lib/requirejs/text',
        'jquery' : 'lib/jquery/jquery-1.7.1',
        'backbone' : 'lib/backbone/amd/backbone',
        'underscore' : 'lib/underscore/amd/underscore',
        'fixture.dom' : 'lib/fixture/jquery.dom.fixture',
        'fixture.string' : 'lib/fixture/jquery.lang.string',
        'fixture.object' : 'lib/fixture/jquery.lang.object',
        'fixtures' : 'fixture/fixtures',
        'qunit' : 'lib/qunit/qunit-1.10.0',
        'equiv' : 'lib/qunit/equiv',
        'qunit.adapter' : 'lib/qunit/QUnitAdapter'
    }
}, [], function() {
    module('Module 1', {});

    test('test 1', 1, function() {
        ok(true, 'passed');
    });

    asyncTest('test 2', 1, function() {
        start();
        ok(true, 'passed');

    });
});

Server starting command (from the same directory JSTD JAR is in)

java -jar JsTestDriver-1.3.4.b.jar --port 48080

Tests running command (from the same directory JSTD JAR is in)

java -jar JsTestDriver-1.3.4.b.jar --runnerMode PROFILE --reset --dryRunFor all --tests all

What works?

The first, synchronous, test does.

What doesn't work?

The second, asynchronous test doesn't work and times out.

The error

Chrome console

Uncaught TypeError: Cannot read property 'all' of undefined qunit-1.10.0.js:1102
done qunit-1.10.0.js:1102
process qunit-1.10.0.js:1285
(anonymous function) qunit-1.10.0.js:383

Console

setting runnermode PROFILE
Chrome: Reset
Chrome: Reset
Chrome 22.0.1229.64: 1 tests [
Module 1 (/test/test/tests.js)
        test test 1
        test test 2]
.F
Total 2 tests (Passed: 1; Fails: 1; Errors: 0) (30025.00 ms)
  Chrome 22.0.1229.64 Windows: Run 2 tests (Passed: 1; Fails: 1; Errors 0) (30025.00 ms)
    Module 1.test test 2 failed (30023.00 ms): Error: Callback '#1' expired after 30000 ms during test step 'start()'
      Error: Callback '#1' expired after 30000 ms during test step 'start()'

Sep 23, 2012 8:36:44 PM com.google.jstestdriver.ActionRunner runActions
INFO:

Notes

I did download the latest QUnit adapter from here. I also tried a bunch of other, supposedly working, adapters to no avail.

Question

Is this even possible? If so, would someone be so kind to shed some light on the issue?

Thank you.

UPDATE (08.04.14):

Karma. That is all.

ZenMaster
  • 12,363
  • 5
  • 36
  • 59
  • It's been awhile since you posted this question -- did Dilip's suggestion fix your issues or did you come up with something else? Just curious, am in a similar situation. – mrk Feb 07 '13 at 23:07
  • Nope. No luck. On another project of mine, however, I decided to go with Grunt and Phantom.JS for QUnits and it's working OK so far. – ZenMaster Feb 08 '13 at 07:39

1 Answers1

2

In an async test, it does not make sense to put a simple set of statements one after the other to execute. An async test is used mainly if we do not want to stop and start the test while a time taking task is being executed within the test, for example a timeout or an ajax call. To emulate this we can change

asyncTest('test 2', 1, function() {
    start();
    ok(true, 'passed');
});

to

asyncTest('test 2', 1, function() {        
    setTimeout(function(){
        ok(true, 'passed');
        start();
    },2000);    
});

which will work like a charm!!!

Dilip
  • 21
  • 1
  • 1
    Does or doesn't make a lot of sense is a bit of a poetry matter. QUnit allows it OOB and it works. In any case, even with your suggestion, the above setting has severe stability issues. Do you have an actual experience with running the stack above? – ZenMaster Oct 04 '12 at 02:05
  • Actually i was facing the same issue in my test case with the same settings. Once i put it into a setTimeout as shown in my code, it worked. – Dilip Oct 04 '12 at 04:25
  • Hmm. I actually did do what you suggested before. The result was that running with `runningMode PROFILE` was skipping the tests altogether and `runningMode DEBUG` was sometimes working and sometimes failing. If you can share your setup and config, I'll accept the answer. – ZenMaster Oct 04 '12 at 12:51
  • This is the configuration i am using to run the test cases : --port 42442 --config JsTestDriver.conf --browserTimeout 20 --server http://localhost:42442 --browser "C:\Program Files\Internet Explorer\iexplore.exe" --tests all --runnerMode DEBUG – Dilip Oct 04 '12 at 14:00
  • I meant including the jsTestDriver.conf – ZenMaster Oct 05 '12 at 00:56