1
1
/**
2
- * QUnit v1.9 .0 - A JavaScript Unit Testing Framework
2
+ * QUnit v1.10 .0 - A JavaScript Unit Testing Framework
3
3
*
4
- * http://docs.jquery. com/QUnit
4
+ * http://qunitjs. com
5
5
*
6
- * Copyright (c) 2012 John Resig, Jörn Zaefferer
7
- * Dual licensed under the MIT (MIT-LICENSE.txt)
8
- * or GPL (GPL-LICENSE.txt) licenses.
6
+ * Copyright 2012 jQuery Foundation and other contributors
7
+ * Released under the MIT license.
8
+ * http://jquery.org/license
9
9
*/
10
10
11
11
( function ( window ) {
@@ -17,6 +17,8 @@ var QUnit,
17
17
fileName = ( sourceFromStacktrace ( 0 ) || "" ) . replace ( / ( : \d + ) + \) ? / , "" ) . replace ( / .+ \/ / , "" ) ,
18
18
toString = Object . prototype . toString ,
19
19
hasOwn = Object . prototype . hasOwnProperty ,
20
+ // Keep a local reference to Date (GH-283)
21
+ Date = window . Date ,
20
22
defined = {
21
23
setTimeout : typeof window . setTimeout !== "undefined" ,
22
24
sessionStorage : ( function ( ) {
@@ -304,7 +306,8 @@ QUnit = {
304
306
// call on start of module test to prepend name to all tests
305
307
module : function ( name , testEnvironment ) {
306
308
config . currentModule = name ;
307
- config . currentModuleTestEnviroment = testEnvironment ;
309
+ config . currentModuleTestEnvironment = testEnvironment ;
310
+ config . modules [ name ] = true ;
308
311
} ,
309
312
310
313
asyncTest : function ( testName , expected , callback ) {
@@ -336,7 +339,7 @@ QUnit = {
336
339
async : async ,
337
340
callback : callback ,
338
341
module : config . currentModule ,
339
- moduleTestEnvironment : config . currentModuleTestEnviroment ,
342
+ moduleTestEnvironment : config . currentModuleTestEnvironment ,
340
343
stack : sourceFromStacktrace ( 2 )
341
344
} ) ;
342
345
@@ -349,7 +352,11 @@ QUnit = {
349
352
350
353
// Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through.
351
354
expect : function ( asserts ) {
352
- config . current . expected = asserts ;
355
+ if ( arguments . length === 1 ) {
356
+ config . current . expected = asserts ;
357
+ } else {
358
+ return config . current . expected ;
359
+ }
353
360
} ,
354
361
355
362
start : function ( count ) {
@@ -415,6 +422,8 @@ QUnit.assert = {
415
422
416
423
var source ,
417
424
details = {
425
+ module : config . current . module ,
426
+ name : config . current . testName ,
418
427
result : result ,
419
428
message : msg
420
429
} ;
@@ -600,6 +609,9 @@ config = {
600
609
}
601
610
] ,
602
611
612
+ // Set of all modules.
613
+ modules : { } ,
614
+
603
615
// logging callback queues
604
616
begin : [ ] ,
605
617
done : [ ] ,
@@ -710,17 +722,10 @@ extend( QUnit, {
710
722
} ,
711
723
712
724
// Resets the test setup. Useful for tests that modify the DOM.
713
- // If jQuery is available, uses jQuery's html(), otherwise just innerHTML.
714
725
reset : function ( ) {
715
- var fixture ;
716
-
717
- if ( window . jQuery ) {
718
- jQuery ( "#qunit-fixture" ) . html ( config . fixture ) ;
719
- } else {
720
- fixture = id ( "qunit-fixture" ) ;
721
- if ( fixture ) {
722
- fixture . innerHTML = config . fixture ;
723
- }
726
+ var fixture = id ( "qunit-fixture" ) ;
727
+ if ( fixture ) {
728
+ fixture . innerHTML = config . fixture ;
724
729
}
725
730
} ,
726
731
@@ -781,6 +786,8 @@ extend( QUnit, {
781
786
782
787
var output , source ,
783
788
details = {
789
+ module : config . current . module ,
790
+ name : config . current . testName ,
784
791
result : result ,
785
792
message : message ,
786
793
actual : actual ,
@@ -826,6 +833,8 @@ extend( QUnit, {
826
833
827
834
var output ,
828
835
details = {
836
+ module : config . current . module ,
837
+ name : config . current . testName ,
829
838
result : false ,
830
839
message : message
831
840
} ;
@@ -916,7 +925,9 @@ QUnit.load = function() {
916
925
runLoggingCallbacks ( "begin" , QUnit , { } ) ;
917
926
918
927
// Initialize the config, saving the execution queue
919
- var banner , filter , i , label , len , main , ol , toolbar , userAgent , val , urlConfigCheckboxes ,
928
+ var banner , filter , i , label , len , main , ol , toolbar , userAgent , val , urlConfigCheckboxes , moduleFilter ,
929
+ numModules = 0 ,
930
+ moduleFilterHtml = "" ,
920
931
urlConfigHtml = "" ,
921
932
oldconfig = extend ( { } , config ) ;
922
933
@@ -940,6 +951,15 @@ QUnit.load = function() {
940
951
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>" ;
941
952
}
942
953
954
+ moduleFilterHtml += "<label for='qunit-modulefilter'>Module: </label><select id='qunit-modulefilter' name='modulefilter'><option value='' " + ( config . module === undefined ? "selected" : "" ) + ">< All Modules ></option>" ;
955
+ for ( i in config . modules ) {
956
+ if ( config . modules . hasOwnProperty ( i ) ) {
957
+ numModules += 1 ;
958
+ moduleFilterHtml += "<option value='" + encodeURIComponent ( i ) + "' " + ( config . module === i ? "selected" : "" ) + ">" + i + "</option>" ;
959
+ }
960
+ }
961
+ moduleFilterHtml += "</select>" ;
962
+
943
963
// `userAgent` initialized at top of scope
944
964
userAgent = id ( "qunit-userAgent" ) ;
945
965
if ( userAgent ) {
@@ -1002,6 +1022,19 @@ QUnit.load = function() {
1002
1022
window . location = QUnit . url ( params ) ;
1003
1023
} ) ;
1004
1024
toolbar . appendChild ( urlConfigCheckboxes ) ;
1025
+
1026
+ if ( numModules > 1 ) {
1027
+ moduleFilter = document . createElement ( 'span' ) ;
1028
+ moduleFilter . setAttribute ( 'id' , 'qunit-modulefilter-container' ) ;
1029
+ moduleFilter . innerHTML = moduleFilterHtml ;
1030
+ addEvent ( moduleFilter , "change" , function ( ) {
1031
+ var selectBox = moduleFilter . getElementsByTagName ( "select" ) [ 0 ] ,
1032
+ selectedModule = decodeURIComponent ( selectBox . options [ selectBox . selectedIndex ] . value ) ;
1033
+
1034
+ window . location = QUnit . url ( { module : ( selectedModule === "" ) ? undefined : selectedModule } ) ;
1035
+ } ) ;
1036
+ toolbar . appendChild ( moduleFilter ) ;
1037
+ }
1005
1038
}
1006
1039
1007
1040
// `main` initialized at top of scope
@@ -1039,9 +1072,9 @@ window.onerror = function ( error, filePath, linerNr ) {
1039
1072
}
1040
1073
QUnit . pushFailure ( error , filePath + ":" + linerNr ) ;
1041
1074
} else {
1042
- QUnit . test ( "global failure" , function ( ) {
1075
+ QUnit . test ( "global failure" , extend ( function ( ) {
1043
1076
QUnit . pushFailure ( error , filePath + ":" + linerNr ) ;
1044
- } ) ;
1077
+ } , { validTest : validTest } ) ) ;
1045
1078
}
1046
1079
return false ;
1047
1080
}
@@ -1108,6 +1141,11 @@ function done() {
1108
1141
}
1109
1142
}
1110
1143
1144
+ // scroll back to top to show results
1145
+ if ( window . scrollTo ) {
1146
+ window . scrollTo ( 0 , 0 ) ;
1147
+ }
1148
+
1111
1149
runLoggingCallbacks ( "done" , QUnit , {
1112
1150
failed : config . stats . bad ,
1113
1151
passed : passed ,
@@ -1123,6 +1161,12 @@ function validTest( test ) {
1123
1161
module = config . module && config . module . toLowerCase ( ) ,
1124
1162
fullName = ( test . module + ": " + test . testName ) . toLowerCase ( ) ;
1125
1163
1164
+ // Internally-generated tests are always valid
1165
+ if ( test . callback && test . callback . validTest === validTest ) {
1166
+ delete test . callback . validTest ;
1167
+ return true ;
1168
+ }
1169
+
1126
1170
if ( config . testNumber ) {
1127
1171
return test . testNumber === config . testNumber ;
1128
1172
}
@@ -1404,7 +1448,8 @@ QUnit.equiv = (function() {
1404
1448
a . global === b . global &&
1405
1449
// (gmi) ...
1406
1450
a . ignoreCase === b . ignoreCase &&
1407
- a . multiline === b . multiline ;
1451
+ a . multiline === b . multiline &&
1452
+ a . sticky === b . sticky ;
1408
1453
} ,
1409
1454
1410
1455
// - skip when the property is a method of an instance (OOP)
0 commit comments