New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Core: Implements QUnit.skip #652
Changes from 1 commit
43dbed4
e241917
9bff489
0122c75
e172590
7b11fdb
4077358
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
function Test( settings ) { | ||
extend( this, settings ); | ||
this.assert = new Assert( this ); | ||
this.assertions = []; | ||
this.testNumber = ++Test.count; | ||
this.module = config.currentModule; | ||
this.moduleTestEnvironment = config.currentModuleTestEnvironment; | ||
this.stack = sourceFromStacktrace( 3 ); | ||
|
||
if ( settings.skip ) { | ||
|
||
// Skipped tests will fully ignore any sent callback | ||
this.callback = function() {}; | ||
this.async = false; | ||
this.expected = 0; | ||
} else { | ||
this.assert = new Assert( this ); | ||
} | ||
} | ||
|
||
Test.count = 0; | ||
|
@@ -102,6 +114,11 @@ Test.prototype = { | |
hooks: function( handler ) { | ||
var hooks = []; | ||
|
||
// hooks are also ignored on skipped tests | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uppcase first char in line comments |
||
if ( this.skip ) { | ||
return hooks; | ||
} | ||
|
||
if ( QUnit.objectType( config[ handler ] ) === "function" ) { | ||
hooks.push( this.queueHook( config[ handler ], handler ) ); | ||
} | ||
|
@@ -139,6 +156,7 @@ Test.prototype = { | |
runLoggingCallbacks( "testDone", { | ||
name: this.testName, | ||
module: this.module, | ||
skipped: !!this.skip, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to js-reporters/js-reporters#4: I'm thinking we'll probably end up standardizing this to be a more generic property like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should just proceed by leaving this as a QUnit-specific thing for now and we can update in QUnit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, I've preferred to keep it as it is before it's definition on the js-reporter. |
||
failed: bad, | ||
passed: this.assertions.length - bad, | ||
total: this.assertions.length, | ||
|
@@ -159,6 +177,10 @@ Test.prototype = { | |
var bad, | ||
test = this; | ||
|
||
if ( !this.valid() ) { | ||
return; | ||
} | ||
|
||
function run() { | ||
|
||
// each of these can by async | ||
|
@@ -250,6 +272,47 @@ Test.prototype = { | |
result: false, | ||
message: message | ||
}); | ||
}, | ||
|
||
/** @return Boolean: true if this test should be ran */ | ||
valid: function() { | ||
var include, | ||
filter = config.filter && config.filter.toLowerCase(), | ||
module = config.module && config.module.toLowerCase(), | ||
fullName = ( this.module + ": " + this.testName ).toLowerCase(); | ||
|
||
// Internally-generated tests are always valid | ||
if ( this.callback && this.callback.validTest ) { | ||
delete this.callback.validTest; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This used to be a function reference, removing it made a little bit of sense for memory management. Now its just a boolean, so we can just leave the property. If that's correct, let's remove this line. |
||
return true; | ||
} | ||
|
||
if ( config.testNumber.length > 0 ) { | ||
if ( inArray( this.testNumber, config.testNumber ) < 0 ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While we're here, let's merge these two if statements. |
||
return false; | ||
} | ||
} | ||
|
||
if ( module && ( !this.module || this.module.toLowerCase() !== module ) ) { | ||
return false; | ||
} | ||
|
||
if ( !filter ) { | ||
return true; | ||
} | ||
|
||
include = filter.charAt( 0 ) !== "!"; | ||
if ( !include ) { | ||
filter = filter.slice( 1 ); | ||
} | ||
|
||
// If the filter matches, we need to honour include | ||
if ( fullName.indexOf( filter ) !== -1 ) { | ||
return include; | ||
} | ||
|
||
// Otherwise, do the opposite | ||
return !include; | ||
} | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this "Skipped", add a CSS rule to show it uppercase. Allows themes to override that.