Skip to content

Commit

Permalink
Core: Implements QUnit.skip
Browse files Browse the repository at this point in the history
Also logs skipped tests on testDone callback that are handled on the html reporter

Fixes #637
Fixes #434
  • Loading branch information
leobalter committed Sep 5, 2014
1 parent 76ff48c commit 8189558
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 2 deletions.
3 changes: 3 additions & 0 deletions reporter/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,9 @@ QUnit.testDone(function( details ) {
time.innerHTML = details.runtime + " ms";

testItem.className = bad ? "fail" : "pass";
if ( details.skipped ) {
addClass( testItem, "skipped" );
}

testItem.insertBefore( time, assertList );
});
Expand Down
19 changes: 19 additions & 0 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,25 @@ QUnit = {
test.queue();
},

skip: function( testName ) {
var test = new Test({
skip: true,
testName: testName,
expected: 0,
async: false,
callback: function() {},
module: config.currentModule,
moduleTestEnvironment: config.currentModuleTestEnvironment,
stack: sourceFromStacktrace( 2 )
});

if ( !validTest( test ) ) {
return;
}

test.queue();
},

start: function( count ) {
var message;

Expand Down
5 changes: 5 additions & 0 deletions src/qunit.css
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@

#qunit-banner.qunit-fail { background-color: #EE5757; }

/*** Skipped tests */

#qunit-tests .skipped {
background-color: #EBECE9;
}

/** Result */

Expand Down
13 changes: 12 additions & 1 deletion src/test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
function Test( settings ) {
extend( this, settings );
this.assert = new Assert( this );
this.assertions = [];
this.testNumber = ++Test.count;

if ( settings.skip ) {
this.testName = "SKIPPED - " + this.testName;
} else {
this.assert = new Assert( this );
}
}

Test.count = 0;
Expand Down Expand Up @@ -102,6 +107,11 @@ Test.prototype = {
hooks: function( handler ) {
var hooks = [];

// hooks are also ignored on skipped tests
if ( this.skip ) {
return hooks;
}

if ( QUnit.objectType( config[ handler ] ) === "function" ) {
hooks.push( this.queueHook( config[ handler ], handler ) );
}
Expand Down Expand Up @@ -139,6 +149,7 @@ Test.prototype = {
runLoggingCallbacks( "testDone", {
name: this.testName,
module: this.module,
skipped: !!this.skip,
failed: bad,
passed: this.assertions.length - bad,
total: this.assertions.length,
Expand Down
3 changes: 2 additions & 1 deletion test/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ QUnit.test( "test2", function( assert ) {
failed: 0,
passed: 17,
total: 17,
testNumber: 1
testNumber: 1,
skipped: false
}, "testDone context" );
assert.deepEqual( testContext, {
module: "logs1",
Expand Down
22 changes: 22 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,25 @@ QUnit.test( "mod2", function( assert ) {
assert.mod2( 2, 0, "2 % 2 == 0" );
assert.mod2( 3, 1, "3 % 2 == 1" );
});

QUnit.module( "QUnit.skip", {
beforeEach: function( assert ) {

// skip test hooks for skipped tests
assert.ok( false, "skipped function" );
throw "Error";
},
afterEach: function( assert ) {
assert.ok( false, "skipped function" );
throw "Error";
}
});

QUnit.skip( "test blocks are skipped", function( assert ) {

// this test callback won't run, even with broken code
assert.expect( 1000 );
throw "Error";
});

QUnit.skip ( "no function" );

0 comments on commit 8189558

Please sign in to comment.