@@ -19,7 +19,7 @@ var defined = {
19
19
return false ;
20
20
}
21
21
} ) ( )
22
- }
22
+ } ;
23
23
24
24
var testId = 0 ;
25
25
@@ -40,6 +40,7 @@ Test.prototype = {
40
40
b . innerHTML = "Running " + this . name ;
41
41
var li = document . createElement ( "li" ) ;
42
42
li . appendChild ( b ) ;
43
+ li . className = "running" ;
43
44
li . id = this . id = "test-output" + testId ++ ;
44
45
tests . appendChild ( li ) ;
45
46
}
@@ -151,7 +152,7 @@ Test.prototype = {
151
152
}
152
153
153
154
// 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 ) ;
155
156
156
157
if ( bad == 0 ) {
157
158
ol . style . display = "none" ;
@@ -171,7 +172,7 @@ Test.prototype = {
171
172
target = target . parentNode ;
172
173
}
173
174
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, "" ) } ) ;
175
176
}
176
177
} ) ;
177
178
@@ -226,15 +227,15 @@ Test.prototype = {
226
227
} ) ;
227
228
}
228
229
// 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 ) ;
230
231
if ( bad ) {
231
232
run ( ) ;
232
233
} else {
233
234
synchronize ( run ) ;
234
235
} ;
235
236
}
236
237
237
- }
238
+ } ;
238
239
239
240
var QUnit = {
240
241
@@ -411,8 +412,18 @@ var QUnit = {
411
412
QUnit . start ( ) ;
412
413
} , timeout ) ;
413
414
}
414
- }
415
+ } ,
415
416
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
+ }
416
427
} ;
417
428
418
429
// Backwards compatibility, deprecated
@@ -425,33 +436,40 @@ var config = {
425
436
queue : [ ] ,
426
437
427
438
// 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
429
447
} ;
430
448
431
449
// Load paramaters
432
450
( function ( ) {
433
451
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
+ }
449
467
}
450
468
}
451
-
452
- // restrict modules/tests by get parameters
453
- config . filters = GETParams ;
454
-
469
+
470
+ QUnit . urlParams = urlParams ;
471
+ config . filter = urlParams . filter ;
472
+
455
473
// Figure out if we're running the tests from a server or not
456
474
QUnit . isLocal = ! ! ( location . protocol === 'file:' ) ;
457
475
} ) ( ) ;
@@ -480,7 +498,7 @@ extend(QUnit, {
480
498
blocking : false ,
481
499
autostart : true ,
482
500
autorun : false ,
483
- filters : [ ] ,
501
+ filter : "" ,
484
502
queue : [ ] ,
485
503
semaphore : 0
486
504
} ) ;
@@ -656,16 +674,14 @@ addEvent(window, "load", function() {
656
674
}
657
675
var banner = id ( "qunit-header" ) ;
658
676
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> › <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
+ } ) ;
669
685
}
670
686
671
687
var toolbar = id ( "qunit-testrunner-toolbar" ) ;
@@ -755,28 +771,24 @@ function done() {
755
771
}
756
772
757
773
function validTest ( name ) {
758
- var i = config . filters . length ,
774
+ var filter = config . filter ,
759
775
run = false ;
760
776
761
- if ( ! i ) {
777
+ if ( ! filter ) {
762
778
return true ;
763
779
}
764
-
765
- while ( i -- ) {
766
- var filter = config . filters [ i ] ,
767
- not = filter . charAt ( 0 ) == '!' ;
768
780
769
- if ( not ) {
770
- filter = filter . slice ( 1 ) ;
771
- }
781
+ not = filter . charAt ( 0 ) === "!" ;
782
+ if ( not ) {
783
+ filter = filter . slice ( 1 ) ;
784
+ }
772
785
773
- if ( name . indexOf ( filter ) !== - 1 ) {
774
- return ! not ;
775
- }
786
+ if ( name . indexOf ( filter ) !== - 1 ) {
787
+ return ! not ;
788
+ }
776
789
777
- if ( not ) {
778
- run = true ;
779
- }
790
+ if ( not ) {
791
+ run = true ;
780
792
}
781
793
782
794
return run ;
@@ -894,7 +906,11 @@ function fail(message, exception, callback) {
894
906
895
907
function extend ( a , b ) {
896
908
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
+ }
898
914
}
899
915
900
916
return a ;
@@ -1185,7 +1201,7 @@ QUnit.jsDump = (function() {
1185
1201
error :'[ERROR]' , //when no parser is found, shouldn't happen
1186
1202
unknown : '[Unknown]' ,
1187
1203
'null' :'null' ,
1188
- undefined :'undefined' ,
1204
+ ' undefined' :'undefined' ,
1189
1205
'function' :function ( fn ) {
1190
1206
var ret = 'function' ,
1191
1207
name = 'name' in fn ? fn . name : ( reName . exec ( fn ) || [ ] ) [ 1 ] ; //functions never have name in IE
0 commit comments