Skip to content

Commit 0a4c334

Browse files
committed
Update to QUnit 1.9.0 and use new urlConfig for custom checkboxes
1 parent b2b5479 commit 0a4c334

File tree

3 files changed

+121
-47
lines changed

3 files changed

+121
-47
lines changed

external/qunit.css

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* QUnit v1.8.0 - A JavaScript Unit Testing Framework
2+
* QUnit v1.9.0 - A JavaScript Unit Testing Framework
33
*
44
* http://docs.jquery.com/QUnit
55
*
@@ -38,10 +38,10 @@
3838
line-height: 1em;
3939
font-weight: normal;
4040

41-
border-radius: 15px 15px 0 0;
42-
-moz-border-radius: 15px 15px 0 0;
43-
-webkit-border-top-right-radius: 15px;
44-
-webkit-border-top-left-radius: 15px;
41+
border-radius: 5px 5px 0 0;
42+
-moz-border-radius: 5px 5px 0 0;
43+
-webkit-border-top-right-radius: 5px;
44+
-webkit-border-top-left-radius: 5px;
4545
}
4646

4747
#qunit-header a {
@@ -54,9 +54,9 @@
5454
color: #fff;
5555
}
5656

57-
#qunit-header label {
57+
#qunit-testrunner-toolbar label {
5858
display: inline-block;
59-
padding-left: 0.5em;
59+
padding: 0 .5em 0 .1em;
6060
}
6161

6262
#qunit-banner {
@@ -113,13 +113,9 @@
113113

114114
background-color: #fff;
115115

116-
border-radius: 15px;
117-
-moz-border-radius: 15px;
118-
-webkit-border-radius: 15px;
119-
120-
box-shadow: inset 0px 2px 13px #999;
121-
-moz-box-shadow: inset 0px 2px 13px #999;
122-
-webkit-box-shadow: inset 0px 2px 13px #999;
116+
border-radius: 5px;
117+
-moz-border-radius: 5px;
118+
-webkit-border-radius: 5px;
123119
}
124120

125121
#qunit-tests table {
@@ -162,8 +158,7 @@
162158
#qunit-tests b.failed { color: #710909; }
163159

164160
#qunit-tests li li {
165-
margin: 0.5em;
166-
padding: 0.4em 0.5em 0.4em 0.5em;
161+
padding: 5px;
167162
background-color: #fff;
168163
border-bottom: none;
169164
list-style-position: inside;
@@ -172,9 +167,9 @@
172167
/*** Passing Styles */
173168

174169
#qunit-tests li li.pass {
175-
color: #5E740B;
170+
color: #3c510c;
176171
background-color: #fff;
177-
border-left: 26px solid #C6E746;
172+
border-left: 10px solid #C6E746;
178173
}
179174

180175
#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
@@ -190,15 +185,15 @@
190185
#qunit-tests li li.fail {
191186
color: #710909;
192187
background-color: #fff;
193-
border-left: 26px solid #EE5757;
188+
border-left: 10px solid #EE5757;
194189
white-space: pre;
195190
}
196191

197192
#qunit-tests > li:last-child {
198-
border-radius: 0 0 15px 15px;
199-
-moz-border-radius: 0 0 15px 15px;
200-
-webkit-border-bottom-right-radius: 15px;
201-
-webkit-border-bottom-left-radius: 15px;
193+
border-radius: 0 0 5px 5px;
194+
-moz-border-radius: 0 0 5px 5px;
195+
-webkit-border-bottom-right-radius: 5px;
196+
-webkit-border-bottom-left-radius: 5px;
202197
}
203198

204199
#qunit-tests .fail { color: #000000; background-color: #EE5757; }

external/qunit.js

Lines changed: 91 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* QUnit v1.8.0 - A JavaScript Unit Testing Framework
2+
* QUnit v1.9.0 - A JavaScript Unit Testing Framework
33
*
44
* http://docs.jquery.com/QUnit
55
*
@@ -403,6 +403,8 @@ QUnit = {
403403
QUnit.assert = {
404404
/**
405405
* Asserts rough true-ish result.
406+
* @name ok
407+
* @function
406408
* @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" );
407409
*/
408410
ok: function( result, msg ) {
@@ -437,36 +439,59 @@ QUnit.assert = {
437439
/**
438440
* Assert that the first two arguments are equal, with an optional message.
439441
* Prints out both actual and expected values.
442+
* @name equal
443+
* @function
440444
* @example equal( format( "Received {0} bytes.", 2), "Received 2 bytes.", "format() replaces {0} with next argument" );
441445
*/
442446
equal: function( actual, expected, message ) {
443447
QUnit.push( expected == actual, actual, expected, message );
444448
},
445449

450+
/**
451+
* @name notEqual
452+
* @function
453+
*/
446454
notEqual: function( actual, expected, message ) {
447455
QUnit.push( expected != actual, actual, expected, message );
448456
},
449457

458+
/**
459+
* @name deepEqual
460+
* @function
461+
*/
450462
deepEqual: function( actual, expected, message ) {
451463
QUnit.push( QUnit.equiv(actual, expected), actual, expected, message );
452464
},
453465

466+
/**
467+
* @name notDeepEqual
468+
* @function
469+
*/
454470
notDeepEqual: function( actual, expected, message ) {
455471
QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message );
456472
},
457473

474+
/**
475+
* @name strictEqual
476+
* @function
477+
*/
458478
strictEqual: function( actual, expected, message ) {
459479
QUnit.push( expected === actual, actual, expected, message );
460480
},
461481

482+
/**
483+
* @name notStrictEqual
484+
* @function
485+
*/
462486
notStrictEqual: function( actual, expected, message ) {
463487
QUnit.push( expected !== actual, actual, expected, message );
464488
},
465489

466-
raises: function( block, expected, message ) {
490+
throws: function( block, expected, message ) {
467491
var actual,
468492
ok = false;
469493

494+
// 'expected' is optional
470495
if ( typeof expected === "string" ) {
471496
message = expected;
472497
expected = null;
@@ -494,18 +519,29 @@ QUnit.assert = {
494519
} else if ( expected.call( {}, actual ) === true ) {
495520
ok = true;
496521
}
497-
}
498522

499-
QUnit.push( ok, actual, null, message );
523+
QUnit.push( ok, actual, null, message );
524+
} else {
525+
QUnit.pushFailure( message, null, 'No exception was thrown.' );
526+
}
500527
}
501528
};
502529

503-
// @deprecated: Kept assertion helpers in root for backwards compatibility
530+
/**
531+
* @deprecate since 1.8.0
532+
* Kept assertion helpers in root for backwards compatibility
533+
*/
504534
extend( QUnit, QUnit.assert );
505535

506536
/**
507-
* @deprecated: Kept for backwards compatibility
508-
* next step: remove entirely
537+
* @deprecated since 1.9.0
538+
* Kept global "raises()" for backwards compatibility
539+
*/
540+
QUnit.raises = QUnit.assert.throws;
541+
542+
/**
543+
* @deprecated since 1.0.0, replaced with error pushes since 1.3.0
544+
* Kept to avoid TypeErrors for undefined methods.
509545
*/
510546
QUnit.equals = function() {
511547
QUnit.push( false, false, false, "QUnit.equals has been deprecated since 2009 (e88049a0), use QUnit.equal instead" );
@@ -549,7 +585,20 @@ config = {
549585
// when enabled, all tests must call expect()
550586
requireExpects: false,
551587

552-
urlConfig: [ "noglobals", "notrycatch" ],
588+
// add checkboxes that are persisted in the query-string
589+
// when enabled, the id is set to `true` as a `QUnit.config` property
590+
urlConfig: [
591+
{
592+
id: "noglobals",
593+
label: "Check for Globals",
594+
tooltip: "Enabling this will test if any test introduces new properties on the `window` object. Stored as query-strings."
595+
},
596+
{
597+
id: "notrycatch",
598+
label: "No try-catch",
599+
tooltip: "Enabling this will run tests outside of a try-catch block. Makes debugging exceptions in IE reasonable. Stored as query-strings."
600+
}
601+
],
553602

554603
// logging callback queues
555604
begin: [],
@@ -770,7 +819,7 @@ extend( QUnit, {
770819
});
771820
},
772821

773-
pushFailure: function( message, source ) {
822+
pushFailure: function( message, source, actual ) {
774823
if ( !config.current ) {
775824
throw new Error( "pushFailure() assertion outside test context, was " + sourceFromStacktrace(2) );
776825
}
@@ -781,15 +830,23 @@ extend( QUnit, {
781830
message: message
782831
};
783832

784-
message = escapeInnerText(message ) || "error";
833+
message = escapeInnerText( message ) || "error";
785834
message = "<span class='test-message'>" + message + "</span>";
786835
output = message;
787836

837+
output += "<table>";
838+
839+
if ( actual ) {
840+
output += "<tr class='test-actual'><th>Result: </th><td><pre>" + escapeInnerText( actual ) + "</pre></td></tr>";
841+
}
842+
788843
if ( source ) {
789844
details.source = source;
790-
output += "<table><tr class='test-source'><th>Source: </th><td><pre>" + escapeInnerText( source ) + "</pre></td></tr></table>";
845+
output += "<tr class='test-source'><th>Source: </th><td><pre>" + escapeInnerText( source ) + "</pre></td></tr>";
791846
}
792847

848+
output += "</table>";
849+
793850
runLoggingCallbacks( "log", QUnit, details );
794851

795852
config.current.assertions.push({
@@ -859,7 +916,7 @@ QUnit.load = function() {
859916
runLoggingCallbacks( "begin", QUnit, {} );
860917

861918
// Initialize the config, saving the execution queue
862-
var banner, filter, i, label, len, main, ol, toolbar, userAgent, val,
919+
var banner, filter, i, label, len, main, ol, toolbar, userAgent, val, urlConfigCheckboxes,
863920
urlConfigHtml = "",
864921
oldconfig = extend( {}, config );
865922

@@ -872,8 +929,15 @@ QUnit.load = function() {
872929

873930
for ( i = 0; i < len; i++ ) {
874931
val = config.urlConfig[i];
875-
config[val] = QUnit.urlParams[val];
876-
urlConfigHtml += "<label><input name='" + val + "' type='checkbox'" + ( config[val] ? " checked='checked'" : "" ) + ">" + val + "</label>";
932+
if ( typeof val === "string" ) {
933+
val = {
934+
id: val,
935+
label: val,
936+
tooltip: "[no tooltip available]"
937+
};
938+
}
939+
config[ val.id ] = QUnit.urlParams[ val.id ];
940+
urlConfigHtml += "<input id='qunit-urlconfig-" + val.id + "' name='" + val.id + "' type='checkbox'" + ( config[ val.id ] ? " checked='checked'" : "" ) + " title='" + val.tooltip + "'><label for='qunit-urlconfig-" + val.id + "' title='" + val.tooltip + "'>" + val.label + "</label>";
877941
}
878942

879943
// `userAgent` initialized at top of scope
@@ -885,12 +949,7 @@ QUnit.load = function() {
885949
// `banner` initialized at top of scope
886950
banner = id( "qunit-header" );
887951
if ( banner ) {
888-
banner.innerHTML = "<a href='" + QUnit.url({ filter: undefined }) + "'>" + banner.innerHTML + "</a> " + urlConfigHtml;
889-
addEvent( banner, "change", function( event ) {
890-
var params = {};
891-
params[ event.target.name ] = event.target.checked ? true : undefined;
892-
window.location = QUnit.url( params );
893-
});
952+
banner.innerHTML = "<a href='" + QUnit.url({ filter: undefined, module: undefined, testNumber: undefined }) + "'>" + banner.innerHTML + "</a> ";
894953
}
895954

896955
// `toolbar` initialized at top of scope
@@ -931,8 +990,18 @@ QUnit.load = function() {
931990
// `label` initialized at top of scope
932991
label = document.createElement( "label" );
933992
label.setAttribute( "for", "qunit-filter-pass" );
993+
label.setAttribute( "title", "Only show tests and assertons that fail. Stored in sessionStorage." );
934994
label.innerHTML = "Hide passed tests";
935995
toolbar.appendChild( label );
996+
997+
urlConfigCheckboxes = document.createElement( 'span' );
998+
urlConfigCheckboxes.innerHTML = urlConfigHtml;
999+
addEvent( urlConfigCheckboxes, "change", function( event ) {
1000+
var params = {};
1001+
params[ event.target.name ] = event.target.checked ? true : undefined;
1002+
window.location = QUnit.url( params );
1003+
});
1004+
toolbar.appendChild( urlConfigCheckboxes );
9361005
}
9371006

9381007
// `main` initialized at top of scope
@@ -1051,14 +1120,14 @@ function done() {
10511120
function validTest( test ) {
10521121
var include,
10531122
filter = config.filter && config.filter.toLowerCase(),
1054-
module = config.module,
1123+
module = config.module && config.module.toLowerCase(),
10551124
fullName = (test.module + ": " + test.testName).toLowerCase();
10561125

10571126
if ( config.testNumber ) {
10581127
return test.testNumber === config.testNumber;
10591128
}
10601129

1061-
if ( module && test.module !== module ) {
1130+
if ( module && ( !test.module || test.module.toLowerCase() !== module ) ) {
10621131
return false;
10631132
}
10641133

tests/unit/testsuite.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ function includeScript( url ) {
1212

1313
QUnit.config.requireExpects = true;
1414

15-
QUnit.config.urlConfig.push( "min" );
15+
QUnit.config.urlConfig.push({
16+
id: "min",
17+
label: "Minified source",
18+
tooltip: "Load minified source files instead of the regular unminified ones."
19+
});
20+
1621
TestHelpers.loadResources = QUnit.urlParams.min ?
1722
function() {
1823
// TODO: proper include with theme images
@@ -28,7 +33,12 @@ TestHelpers.loadResources = QUnit.urlParams.min ?
2833
});
2934
};
3035

31-
QUnit.config.urlConfig.push( "nojshint" );
36+
QUnit.config.urlConfig.push({
37+
id: "nojshint",
38+
label: "Skip JSHint",
39+
tooltip: "Skip running JSHint, e.g. within TestSwarm, where Jenkins runs it already"
40+
});
41+
3242
var jshintLoaded = false;
3343
TestHelpers.testJshint = function( module ) {
3444
if ( QUnit.urlParams.nojshint ) {

0 commit comments

Comments
 (0)