Skip to content

Commit 08fe43e

Browse files
committed
Update to latest QUnit
1 parent 5d780f9 commit 08fe43e

File tree

1 file changed

+70
-54
lines changed

1 file changed

+70
-54
lines changed

test/qunit/qunit.js

Lines changed: 70 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var defined = {
1919
return false;
2020
}
2121
})()
22-
}
22+
};
2323

2424
var testId = 0;
2525

@@ -40,6 +40,7 @@ Test.prototype = {
4040
b.innerHTML = "Running " + this.name;
4141
var li = document.createElement("li");
4242
li.appendChild( b );
43+
li.className = "running";
4344
li.id = this.id = "test-output" + testId++;
4445
tests.appendChild( li );
4546
}
@@ -151,7 +152,7 @@ Test.prototype = {
151152
}
152153

153154
// store result when possible
154-
defined.sessionStorage && sessionStorage.setItem("qunit-" + this.testName, bad);
155+
QUnit.config.reorder && defined.sessionStorage && sessionStorage.setItem("qunit-" + this.testName, bad);
155156

156157
if (bad == 0) {
157158
ol.style.display = "none";
@@ -171,7 +172,7 @@ Test.prototype = {
171172
target = target.parentNode;
172173
}
173174
if ( window.location && target.nodeName.toLowerCase() === "strong" ) {
174-
window.location.search = "?" + encodeURIComponent(getText([target]).replace(/\(.+\)$/, "").replace(/(^\s*|\s*$)/g, ""));
175+
window.location = QUnit.url({ filter: getText([target]).replace(/\(.+\)$/, "").replace(/(^\s*|\s*$)/g, "") });
175176
}
176177
});
177178

@@ -226,15 +227,15 @@ Test.prototype = {
226227
});
227228
}
228229
// defer when previous test run passed, if storage is available
229-
var bad = defined.sessionStorage && +sessionStorage.getItem("qunit-" + this.testName);
230+
var bad = QUnit.config.reorder && defined.sessionStorage && +sessionStorage.getItem("qunit-" + this.testName);
230231
if (bad) {
231232
run();
232233
} else {
233234
synchronize(run);
234235
};
235236
}
236237

237-
}
238+
};
238239

239240
var QUnit = {
240241

@@ -411,8 +412,18 @@ var QUnit = {
411412
QUnit.start();
412413
}, timeout);
413414
}
414-
}
415+
},
415416

417+
url: function( params ) {
418+
params = extend( extend( {}, QUnit.urlParams ), params );
419+
var querystring = "?",
420+
key;
421+
for ( key in params ) {
422+
querystring += encodeURIComponent( key ) + "=" +
423+
encodeURIComponent( params[ key ] ) + "&";
424+
}
425+
return window.location.pathname + querystring.slice( 0, -1 );
426+
}
416427
};
417428

418429
// Backwards compatibility, deprecated
@@ -425,33 +436,40 @@ var config = {
425436
queue: [],
426437

427438
// block until document ready
428-
blocking: true
439+
blocking: true,
440+
441+
// by default, run previously failed tests first
442+
// very useful in combination with "Hide passed tests" checked
443+
reorder: true,
444+
445+
noglobals: false,
446+
notrycatch: false
429447
};
430448

431449
// Load paramaters
432450
(function() {
433451
var location = window.location || { search: "", protocol: "file:" },
434-
GETParams = location.search.slice(1).split('&');
435-
436-
for ( var i = 0; i < GETParams.length; i++ ) {
437-
GETParams[i] = decodeURIComponent( GETParams[i] );
438-
if ( GETParams[i] === "noglobals" ) {
439-
GETParams.splice( i, 1 );
440-
i--;
441-
config.noglobals = true;
442-
} else if ( GETParams[i] === "notrycatch" ) {
443-
GETParams.splice( i, 1 );
444-
i--;
445-
config.notrycatch = true;
446-
} else if ( GETParams[i].search('=') > -1 ) {
447-
GETParams.splice( i, 1 );
448-
i--;
452+
params = location.search.slice( 1 ).split( "&" ),
453+
length = params.length,
454+
urlParams = {},
455+
current;
456+
457+
if ( params[ 0 ] ) {
458+
for ( var i = 0; i < length; i++ ) {
459+
current = params[ i ].split( "=" );
460+
current[ 0 ] = decodeURIComponent( current[ 0 ] );
461+
// allow just a key to turn on a flag, e.g., test.html?noglobals
462+
current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true;
463+
urlParams[ current[ 0 ] ] = current[ 1 ];
464+
if ( current[ 0 ] in config ) {
465+
config[ current[ 0 ] ] = current[ 1 ];
466+
}
449467
}
450468
}
451-
452-
// restrict modules/tests by get parameters
453-
config.filters = GETParams;
454-
469+
470+
QUnit.urlParams = urlParams;
471+
config.filter = urlParams.filter;
472+
455473
// Figure out if we're running the tests from a server or not
456474
QUnit.isLocal = !!(location.protocol === 'file:');
457475
})();
@@ -480,7 +498,7 @@ extend(QUnit, {
480498
blocking: false,
481499
autostart: true,
482500
autorun: false,
483-
filters: [],
501+
filter: "",
484502
queue: [],
485503
semaphore: 0
486504
});
@@ -656,16 +674,14 @@ addEvent(window, "load", function() {
656674
}
657675
var banner = id("qunit-header");
658676
if ( banner ) {
659-
var paramsIndex = location.href.lastIndexOf(location.search);
660-
if ( paramsIndex > -1 ) {
661-
var mainPageLocation = location.href.slice(0, paramsIndex);
662-
if ( mainPageLocation == location.href ) {
663-
banner.innerHTML = '<a href=""> ' + banner.innerHTML + '</a> ';
664-
} else {
665-
var testName = decodeURIComponent(location.search.slice(1));
666-
banner.innerHTML = '<a href="' + mainPageLocation + '">' + banner.innerHTML + '</a> &#8250; <a href="">' + testName + '</a>';
667-
}
668-
}
677+
banner.innerHTML = '<a href="' + QUnit.url({ filter: undefined }) + '"> ' + banner.innerHTML + '</a> ' +
678+
'<label><input name="noglobals" type="checkbox"' + ( config.noglobals ? ' checked="checked"' : '' ) + '>noglobals</label>' +
679+
'<label><input name="notrycatch" type="checkbox"' + ( config.notrycatch ? ' checked="checked"' : '' ) + '>notrycatch</label>';
680+
addEvent( banner, "change", function( event ) {
681+
var params = {};
682+
params[ event.target.name ] = event.target.checked ? true : undefined;
683+
window.location = QUnit.url( params );
684+
});
669685
}
670686

671687
var toolbar = id("qunit-testrunner-toolbar");
@@ -755,28 +771,24 @@ function done() {
755771
}
756772

757773
function validTest( name ) {
758-
var i = config.filters.length,
774+
var filter = config.filter,
759775
run = false;
760776

761-
if ( !i ) {
777+
if ( !filter ) {
762778
return true;
763779
}
764-
765-
while ( i-- ) {
766-
var filter = config.filters[i],
767-
not = filter.charAt(0) == '!';
768780

769-
if ( not ) {
770-
filter = filter.slice(1);
771-
}
781+
not = filter.charAt( 0 ) === "!";
782+
if ( not ) {
783+
filter = filter.slice( 1 );
784+
}
772785

773-
if ( name.indexOf(filter) !== -1 ) {
774-
return !not;
775-
}
786+
if ( name.indexOf( filter ) !== -1 ) {
787+
return !not;
788+
}
776789

777-
if ( not ) {
778-
run = true;
779-
}
790+
if ( not ) {
791+
run = true;
780792
}
781793

782794
return run;
@@ -894,7 +906,11 @@ function fail(message, exception, callback) {
894906

895907
function extend(a, b) {
896908
for ( var prop in b ) {
897-
a[prop] = b[prop];
909+
if ( b[prop] === undefined ) {
910+
delete a[prop];
911+
} else {
912+
a[prop] = b[prop];
913+
}
898914
}
899915

900916
return a;
@@ -1185,7 +1201,7 @@ QUnit.jsDump = (function() {
11851201
error:'[ERROR]', //when no parser is found, shouldn't happen
11861202
unknown: '[Unknown]',
11871203
'null':'null',
1188-
undefined:'undefined',
1204+
'undefined':'undefined',
11891205
'function':function( fn ) {
11901206
var ret = 'function',
11911207
name = 'name' in fn ? fn.name : (reName.exec(fn)||[])[1];//functions never have name in IE

0 commit comments

Comments
 (0)