Skip to content

Commit

Permalink
feat: use QUnit to track total number of tests
Browse files Browse the repository at this point in the history
As of qunitjs/qunit#553, QUnit will now provide the total number of tests
to be run in their QUnit.begin callback.  This commit will use that
functionality if available, otherwise it falls back to using the current
manual tracking method with QUnit.testStart
  • Loading branch information
dcherman committed Jun 10, 2014
1 parent 15e7e8c commit 45d75e3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/adapter.js
Expand Up @@ -4,9 +4,22 @@ var createQUnitStartFn = function (tc, runnerPassedIn) {
var totalNumberOfTest = 0;
var timer = null;
var testResult = {};
var supportsTestTracking = false;

if ( runner.begin ) {
runner.begin(function( args ) {
if ( args && typeof args.totalTests === 'number' ) {
tc.info({ total: args.totalTests });
supportsTestTracking = true;
}
});
}

runner.done(function () {
tc.info({ total: totalNumberOfTest });
if ( !supportsTestTracking ) {
tc.info({ total: totalNumberOfTest });
}

tc.complete({
coverage: window.__coverage__
});
Expand Down
35 changes: 35 additions & 0 deletions test/adapter.spec.js
Expand Up @@ -26,6 +26,41 @@ describe('adapter qunit', function() {
});
});

describe('total number of tests', function() {

it('should use the tracking in qunit if available', function() {
spyOn(tc, 'info').andCallFake(function(result) {
expect(result.total).toBe(1);
});

var mockQUnitResult = {
totalTests: 1
};

runner.emit('begin', mockQUnitResult);
expect(tc.info).toHaveBeenCalled();
});

it('should use our own tracking if none is available', function() {
spyOn(tc, 'info').andCallFake(function(result) {
expect(result.total).toBe(1);
});

var mockQUnitResult = {
name: 'should do something',
module: 'desc1',
failed: 0
};

runner.emit('testStart', mockQUnitResult);
runner.emit('testDone', mockQUnitResult);
runner.emit('done');

expect(tc.info).toHaveBeenCalled();
});

});


describe('test end', function() {

Expand Down
4 changes: 4 additions & 0 deletions test/mocks.js
Expand Up @@ -27,6 +27,10 @@ var MockSocket = Emitter;
var MockRunner = function() {
Emitter.call(this);

this.begin = function(fn) {
this.on("begin", fn);
};

this.done = function(fn) {
this.on("done", fn);
};
Expand Down

0 comments on commit 45d75e3

Please sign in to comment.