qunited 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/qunited/driver/support/qunit.js +502 -188
- data/lib/qunited/server/qunit.js +500 -186
- data/lib/qunited/version.rb +1 -1
- data/qunited.gemspec +1 -1
- metadata +8 -9
@@ -1,34 +1,87 @@
|
|
1
1
|
/**
|
2
|
-
* QUnit v1.
|
2
|
+
* QUnit v1.11.0 - A JavaScript Unit Testing Framework
|
3
3
|
*
|
4
|
-
* http://
|
4
|
+
* http://qunitjs.com
|
5
5
|
*
|
6
|
-
* Copyright
|
7
|
-
*
|
8
|
-
*
|
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 ) {
|
12
12
|
|
13
13
|
var QUnit,
|
14
|
+
assert,
|
14
15
|
config,
|
16
|
+
onErrorFnPrev,
|
15
17
|
testId = 0,
|
16
18
|
fileName = (sourceFromStacktrace( 0 ) || "" ).replace(/(:\d+)+\)?/, "").replace(/.+\//, ""),
|
17
19
|
toString = Object.prototype.toString,
|
18
20
|
hasOwn = Object.prototype.hasOwnProperty,
|
21
|
+
// Keep a local reference to Date (GH-283)
|
22
|
+
Date = window.Date,
|
19
23
|
defined = {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
setTimeout: typeof window.setTimeout !== "undefined",
|
25
|
+
sessionStorage: (function() {
|
26
|
+
var x = "qunit-test-string";
|
27
|
+
try {
|
28
|
+
sessionStorage.setItem( x, x );
|
29
|
+
sessionStorage.removeItem( x );
|
30
|
+
return true;
|
31
|
+
} catch( e ) {
|
32
|
+
return false;
|
33
|
+
}
|
34
|
+
}())
|
35
|
+
},
|
36
|
+
/**
|
37
|
+
* Provides a normalized error string, correcting an issue
|
38
|
+
* with IE 7 (and prior) where Error.prototype.toString is
|
39
|
+
* not properly implemented
|
40
|
+
*
|
41
|
+
* Based on http://es5.github.com/#x15.11.4.4
|
42
|
+
*
|
43
|
+
* @param {String|Error} error
|
44
|
+
* @return {String} error message
|
45
|
+
*/
|
46
|
+
errorString = function( error ) {
|
47
|
+
var name, message,
|
48
|
+
errorString = error.toString();
|
49
|
+
if ( errorString.substring( 0, 7 ) === "[object" ) {
|
50
|
+
name = error.name ? error.name.toString() : "Error";
|
51
|
+
message = error.message ? error.message.toString() : "";
|
52
|
+
if ( name && message ) {
|
53
|
+
return name + ": " + message;
|
54
|
+
} else if ( name ) {
|
55
|
+
return name;
|
56
|
+
} else if ( message ) {
|
57
|
+
return message;
|
58
|
+
} else {
|
59
|
+
return "Error";
|
60
|
+
}
|
61
|
+
} else {
|
62
|
+
return errorString;
|
29
63
|
}
|
30
|
-
}
|
31
|
-
|
64
|
+
},
|
65
|
+
/**
|
66
|
+
* Makes a clone of an object using only Array or Object as base,
|
67
|
+
* and copies over the own enumerable properties.
|
68
|
+
*
|
69
|
+
* @param {Object} obj
|
70
|
+
* @return {Object} New object with only the own properties (recursively).
|
71
|
+
*/
|
72
|
+
objectValues = function( obj ) {
|
73
|
+
// Grunt 0.3.x uses an older version of jshint that still has jshint/jshint#392.
|
74
|
+
/*jshint newcap: false */
|
75
|
+
var key, val,
|
76
|
+
vals = QUnit.is( "array", obj ) ? [] : {};
|
77
|
+
for ( key in obj ) {
|
78
|
+
if ( hasOwn.call( obj, key ) ) {
|
79
|
+
val = obj[key];
|
80
|
+
vals[key] = val === Object(val) ? objectValues(val) : val;
|
81
|
+
}
|
82
|
+
}
|
83
|
+
return vals;
|
84
|
+
};
|
32
85
|
|
33
86
|
function Test( settings ) {
|
34
87
|
extend( this, settings );
|
@@ -41,11 +94,11 @@ Test.count = 0;
|
|
41
94
|
Test.prototype = {
|
42
95
|
init: function() {
|
43
96
|
var a, b, li,
|
44
|
-
|
97
|
+
tests = id( "qunit-tests" );
|
45
98
|
|
46
99
|
if ( tests ) {
|
47
100
|
b = document.createElement( "strong" );
|
48
|
-
b.innerHTML = this.
|
101
|
+
b.innerHTML = this.nameHtml;
|
49
102
|
|
50
103
|
// `a` initialized at top of scope
|
51
104
|
a = document.createElement( "a" );
|
@@ -89,6 +142,7 @@ Test.prototype = {
|
|
89
142
|
teardown: function() {}
|
90
143
|
}, this.moduleTestEnvironment );
|
91
144
|
|
145
|
+
this.started = +new Date();
|
92
146
|
runLoggingCallbacks( "testStart", QUnit, {
|
93
147
|
name: this.testName,
|
94
148
|
module: this.module
|
@@ -108,7 +162,7 @@ Test.prototype = {
|
|
108
162
|
try {
|
109
163
|
this.testEnvironment.setup.call( this.testEnvironment );
|
110
164
|
} catch( e ) {
|
111
|
-
QUnit.pushFailure( "Setup failed on " + this.testName + ": " + e.message, extractStacktrace( e, 1 ) );
|
165
|
+
QUnit.pushFailure( "Setup failed on " + this.testName + ": " + ( e.message || e ), extractStacktrace( e, 1 ) );
|
112
166
|
}
|
113
167
|
},
|
114
168
|
run: function() {
|
@@ -117,22 +171,28 @@ Test.prototype = {
|
|
117
171
|
var running = id( "qunit-testresult" );
|
118
172
|
|
119
173
|
if ( running ) {
|
120
|
-
running.innerHTML = "Running: <br/>" + this.
|
174
|
+
running.innerHTML = "Running: <br/>" + this.nameHtml;
|
121
175
|
}
|
122
176
|
|
123
177
|
if ( this.async ) {
|
124
178
|
QUnit.stop();
|
125
179
|
}
|
126
180
|
|
181
|
+
this.callbackStarted = +new Date();
|
182
|
+
|
127
183
|
if ( config.notrycatch ) {
|
128
184
|
this.callback.call( this.testEnvironment, QUnit.assert );
|
185
|
+
this.callbackRuntime = +new Date() - this.callbackStarted;
|
129
186
|
return;
|
130
187
|
}
|
131
188
|
|
132
189
|
try {
|
133
190
|
this.callback.call( this.testEnvironment, QUnit.assert );
|
191
|
+
this.callbackRuntime = +new Date() - this.callbackStarted;
|
134
192
|
} catch( e ) {
|
135
|
-
|
193
|
+
this.callbackRuntime = +new Date() - this.callbackStarted;
|
194
|
+
|
195
|
+
QUnit.pushFailure( "Died on test #" + (this.assertions.length + 1) + " " + this.stack + ": " + ( e.message || e ), extractStacktrace( e, 0 ) );
|
136
196
|
// else next test will carry the responsibility
|
137
197
|
saveGlobal();
|
138
198
|
|
@@ -145,38 +205,43 @@ Test.prototype = {
|
|
145
205
|
teardown: function() {
|
146
206
|
config.current = this;
|
147
207
|
if ( config.notrycatch ) {
|
208
|
+
if ( typeof this.callbackRuntime === "undefined" ) {
|
209
|
+
this.callbackRuntime = +new Date() - this.callbackStarted;
|
210
|
+
}
|
148
211
|
this.testEnvironment.teardown.call( this.testEnvironment );
|
149
212
|
return;
|
150
213
|
} else {
|
151
214
|
try {
|
152
215
|
this.testEnvironment.teardown.call( this.testEnvironment );
|
153
216
|
} catch( e ) {
|
154
|
-
QUnit.pushFailure( "Teardown failed on " + this.testName + ": " + e.message, extractStacktrace( e, 1 ) );
|
217
|
+
QUnit.pushFailure( "Teardown failed on " + this.testName + ": " + ( e.message || e ), extractStacktrace( e, 1 ) );
|
155
218
|
}
|
156
219
|
}
|
157
220
|
checkPollution();
|
158
221
|
},
|
159
222
|
finish: function() {
|
160
223
|
config.current = this;
|
161
|
-
if ( config.requireExpects && this.expected
|
224
|
+
if ( config.requireExpects && this.expected === null ) {
|
162
225
|
QUnit.pushFailure( "Expected number of assertions to be defined, but expect() was not called.", this.stack );
|
163
|
-
} else if ( this.expected
|
226
|
+
} else if ( this.expected !== null && this.expected !== this.assertions.length ) {
|
164
227
|
QUnit.pushFailure( "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run", this.stack );
|
165
|
-
} else if ( this.expected
|
228
|
+
} else if ( this.expected === null && !this.assertions.length ) {
|
166
229
|
QUnit.pushFailure( "Expected at least one assertion, but none were run - call expect(0) to accept zero assertions.", this.stack );
|
167
230
|
}
|
168
231
|
|
169
|
-
var assertion, a, b,
|
232
|
+
var i, assertion, a, b, time, li, ol,
|
170
233
|
test = this,
|
171
234
|
good = 0,
|
172
235
|
bad = 0,
|
173
236
|
tests = id( "qunit-tests" );
|
174
237
|
|
238
|
+
this.runtime = +new Date() - this.started;
|
175
239
|
config.stats.all += this.assertions.length;
|
176
240
|
config.moduleStats.all += this.assertions.length;
|
177
241
|
|
178
242
|
if ( tests ) {
|
179
243
|
ol = document.createElement( "ol" );
|
244
|
+
ol.className = "qunit-assert-list";
|
180
245
|
|
181
246
|
for ( i = 0; i < this.assertions.length; i++ ) {
|
182
247
|
assertion = this.assertions[i];
|
@@ -205,22 +270,22 @@ Test.prototype = {
|
|
205
270
|
}
|
206
271
|
|
207
272
|
if ( bad === 0 ) {
|
208
|
-
ol
|
273
|
+
addClass( ol, "qunit-collapsed" );
|
209
274
|
}
|
210
275
|
|
211
276
|
// `b` initialized at top of scope
|
212
277
|
b = document.createElement( "strong" );
|
213
|
-
b.innerHTML = this.
|
278
|
+
b.innerHTML = this.nameHtml + " <b class='counts'>(<b class='failed'>" + bad + "</b>, <b class='passed'>" + good + "</b>, " + this.assertions.length + ")</b>";
|
214
279
|
|
215
280
|
addEvent(b, "click", function() {
|
216
|
-
var next = b.
|
217
|
-
|
218
|
-
|
281
|
+
var next = b.parentNode.lastChild,
|
282
|
+
collapsed = hasClass( next, "qunit-collapsed" );
|
283
|
+
( collapsed ? removeClass : addClass )( next, "qunit-collapsed" );
|
219
284
|
});
|
220
285
|
|
221
286
|
addEvent(b, "dblclick", function( e ) {
|
222
287
|
var target = e && e.target ? e.target : window.event.srcElement;
|
223
|
-
if ( target.nodeName.toLowerCase()
|
288
|
+
if ( target.nodeName.toLowerCase() === "span" || target.nodeName.toLowerCase() === "b" ) {
|
224
289
|
target = target.parentNode;
|
225
290
|
}
|
226
291
|
if ( window.location && target.nodeName.toLowerCase() === "strong" ) {
|
@@ -228,13 +293,19 @@ Test.prototype = {
|
|
228
293
|
}
|
229
294
|
});
|
230
295
|
|
296
|
+
// `time` initialized at top of scope
|
297
|
+
time = document.createElement( "span" );
|
298
|
+
time.className = "runtime";
|
299
|
+
time.innerHTML = this.runtime + " ms";
|
300
|
+
|
231
301
|
// `li` initialized at top of scope
|
232
302
|
li = id( this.id );
|
233
303
|
li.className = bad ? "fail" : "pass";
|
234
304
|
li.removeChild( li.firstChild );
|
235
305
|
a = li.firstChild;
|
236
306
|
li.appendChild( b );
|
237
|
-
li.appendChild
|
307
|
+
li.appendChild( a );
|
308
|
+
li.appendChild( time );
|
238
309
|
li.appendChild( ol );
|
239
310
|
|
240
311
|
} else {
|
@@ -252,10 +323,13 @@ Test.prototype = {
|
|
252
323
|
module: this.module,
|
253
324
|
failed: bad,
|
254
325
|
passed: this.assertions.length - bad,
|
255
|
-
total: this.assertions.length
|
326
|
+
total: this.assertions.length,
|
327
|
+
duration: this.runtime
|
256
328
|
});
|
257
329
|
|
258
330
|
QUnit.reset();
|
331
|
+
|
332
|
+
config.current = undefined;
|
259
333
|
},
|
260
334
|
|
261
335
|
queue: function() {
|
@@ -301,7 +375,8 @@ QUnit = {
|
|
301
375
|
// call on start of module test to prepend name to all tests
|
302
376
|
module: function( name, testEnvironment ) {
|
303
377
|
config.currentModule = name;
|
304
|
-
config.
|
378
|
+
config.currentModuleTestEnvironment = testEnvironment;
|
379
|
+
config.modules[name] = true;
|
305
380
|
},
|
306
381
|
|
307
382
|
asyncTest: function( testName, expected, callback ) {
|
@@ -315,7 +390,7 @@ QUnit = {
|
|
315
390
|
|
316
391
|
test: function( testName, expected, callback, async ) {
|
317
392
|
var test,
|
318
|
-
|
393
|
+
nameHtml = "<span class='test-name'>" + escapeText( testName ) + "</span>";
|
319
394
|
|
320
395
|
if ( arguments.length === 2 ) {
|
321
396
|
callback = expected;
|
@@ -323,17 +398,17 @@ QUnit = {
|
|
323
398
|
}
|
324
399
|
|
325
400
|
if ( config.currentModule ) {
|
326
|
-
|
401
|
+
nameHtml = "<span class='module-name'>" + escapeText( config.currentModule ) + "</span>: " + nameHtml;
|
327
402
|
}
|
328
403
|
|
329
404
|
test = new Test({
|
330
|
-
|
405
|
+
nameHtml: nameHtml,
|
331
406
|
testName: testName,
|
332
407
|
expected: expected,
|
333
408
|
async: async,
|
334
409
|
callback: callback,
|
335
410
|
module: config.currentModule,
|
336
|
-
moduleTestEnvironment: config.
|
411
|
+
moduleTestEnvironment: config.currentModuleTestEnvironment,
|
337
412
|
stack: sourceFromStacktrace( 2 )
|
338
413
|
});
|
339
414
|
|
@@ -346,10 +421,26 @@ QUnit = {
|
|
346
421
|
|
347
422
|
// Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through.
|
348
423
|
expect: function( asserts ) {
|
349
|
-
|
424
|
+
if (arguments.length === 1) {
|
425
|
+
config.current.expected = asserts;
|
426
|
+
} else {
|
427
|
+
return config.current.expected;
|
428
|
+
}
|
350
429
|
},
|
351
430
|
|
352
431
|
start: function( count ) {
|
432
|
+
// QUnit hasn't been initialized yet.
|
433
|
+
// Note: RequireJS (et al) may delay onLoad
|
434
|
+
if ( config.semaphore === undefined ) {
|
435
|
+
QUnit.begin(function() {
|
436
|
+
// This is triggered at the top of QUnit.load, push start() to the event loop, to allow QUnit.load to finish first
|
437
|
+
setTimeout(function() {
|
438
|
+
QUnit.start( count );
|
439
|
+
});
|
440
|
+
});
|
441
|
+
return;
|
442
|
+
}
|
443
|
+
|
353
444
|
config.semaphore -= count || 1;
|
354
445
|
// don't start until equal number of stop-calls
|
355
446
|
if ( config.semaphore > 0 ) {
|
@@ -358,6 +449,8 @@ QUnit = {
|
|
358
449
|
// ignore if start is called more often then stop
|
359
450
|
if ( config.semaphore < 0 ) {
|
360
451
|
config.semaphore = 0;
|
452
|
+
QUnit.pushFailure( "Called start() while already started (QUnit.config.semaphore was 0 already)", null, sourceFromStacktrace(2) );
|
453
|
+
return;
|
361
454
|
}
|
362
455
|
// A slight delay, to avoid any current callbacks
|
363
456
|
if ( defined.setTimeout ) {
|
@@ -393,13 +486,18 @@ QUnit = {
|
|
393
486
|
}
|
394
487
|
};
|
395
488
|
|
489
|
+
// `assert` initialized at top of scope
|
396
490
|
// Asssert helpers
|
397
|
-
// All of these must call
|
491
|
+
// All of these must either call QUnit.push() or manually do:
|
398
492
|
// - runLoggingCallbacks( "log", .. );
|
399
493
|
// - config.current.assertions.push({ .. });
|
400
|
-
QUnit
|
494
|
+
// We attach it to the QUnit object *after* we expose the public API,
|
495
|
+
// otherwise `assert` will become a global variable in browsers (#341).
|
496
|
+
assert = {
|
401
497
|
/**
|
402
498
|
* Asserts rough true-ish result.
|
499
|
+
* @name ok
|
500
|
+
* @function
|
403
501
|
* @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" );
|
404
502
|
*/
|
405
503
|
ok: function( result, msg ) {
|
@@ -410,18 +508,20 @@ QUnit.assert = {
|
|
410
508
|
|
411
509
|
var source,
|
412
510
|
details = {
|
511
|
+
module: config.current.module,
|
512
|
+
name: config.current.testName,
|
413
513
|
result: result,
|
414
514
|
message: msg
|
415
515
|
};
|
416
516
|
|
417
|
-
msg =
|
517
|
+
msg = escapeText( msg || (result ? "okay" : "failed" ) );
|
418
518
|
msg = "<span class='test-message'>" + msg + "</span>";
|
419
519
|
|
420
520
|
if ( !result ) {
|
421
521
|
source = sourceFromStacktrace( 2 );
|
422
522
|
if ( source ) {
|
423
523
|
details.source = source;
|
424
|
-
msg += "<table><tr class='test-source'><th>Source: </th><td><
|
524
|
+
msg += "<table><tr class='test-source'><th>Source: </th><td><pre>" + escapeText( source ) + "</pre></td></tr></table>";
|
425
525
|
}
|
426
526
|
}
|
427
527
|
runLoggingCallbacks( "log", QUnit, details );
|
@@ -434,36 +534,82 @@ QUnit.assert = {
|
|
434
534
|
/**
|
435
535
|
* Assert that the first two arguments are equal, with an optional message.
|
436
536
|
* Prints out both actual and expected values.
|
537
|
+
* @name equal
|
538
|
+
* @function
|
437
539
|
* @example equal( format( "Received {0} bytes.", 2), "Received 2 bytes.", "format() replaces {0} with next argument" );
|
438
540
|
*/
|
439
541
|
equal: function( actual, expected, message ) {
|
542
|
+
/*jshint eqeqeq:false */
|
440
543
|
QUnit.push( expected == actual, actual, expected, message );
|
441
544
|
},
|
442
545
|
|
546
|
+
/**
|
547
|
+
* @name notEqual
|
548
|
+
* @function
|
549
|
+
*/
|
443
550
|
notEqual: function( actual, expected, message ) {
|
551
|
+
/*jshint eqeqeq:false */
|
444
552
|
QUnit.push( expected != actual, actual, expected, message );
|
445
553
|
},
|
446
554
|
|
555
|
+
/**
|
556
|
+
* @name propEqual
|
557
|
+
* @function
|
558
|
+
*/
|
559
|
+
propEqual: function( actual, expected, message ) {
|
560
|
+
actual = objectValues(actual);
|
561
|
+
expected = objectValues(expected);
|
562
|
+
QUnit.push( QUnit.equiv(actual, expected), actual, expected, message );
|
563
|
+
},
|
564
|
+
|
565
|
+
/**
|
566
|
+
* @name notPropEqual
|
567
|
+
* @function
|
568
|
+
*/
|
569
|
+
notPropEqual: function( actual, expected, message ) {
|
570
|
+
actual = objectValues(actual);
|
571
|
+
expected = objectValues(expected);
|
572
|
+
QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message );
|
573
|
+
},
|
574
|
+
|
575
|
+
/**
|
576
|
+
* @name deepEqual
|
577
|
+
* @function
|
578
|
+
*/
|
447
579
|
deepEqual: function( actual, expected, message ) {
|
448
580
|
QUnit.push( QUnit.equiv(actual, expected), actual, expected, message );
|
449
581
|
},
|
450
582
|
|
583
|
+
/**
|
584
|
+
* @name notDeepEqual
|
585
|
+
* @function
|
586
|
+
*/
|
451
587
|
notDeepEqual: function( actual, expected, message ) {
|
452
588
|
QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message );
|
453
589
|
},
|
454
590
|
|
591
|
+
/**
|
592
|
+
* @name strictEqual
|
593
|
+
* @function
|
594
|
+
*/
|
455
595
|
strictEqual: function( actual, expected, message ) {
|
456
596
|
QUnit.push( expected === actual, actual, expected, message );
|
457
597
|
},
|
458
598
|
|
599
|
+
/**
|
600
|
+
* @name notStrictEqual
|
601
|
+
* @function
|
602
|
+
*/
|
459
603
|
notStrictEqual: function( actual, expected, message ) {
|
460
604
|
QUnit.push( expected !== actual, actual, expected, message );
|
461
605
|
},
|
462
606
|
|
463
|
-
|
607
|
+
"throws": function( block, expected, message ) {
|
464
608
|
var actual,
|
609
|
+
expectedOutput = expected,
|
465
610
|
ok = false;
|
466
611
|
|
612
|
+
// 'expected' is optional
|
467
613
|
if ( typeof expected === "string" ) {
|
468
614
|
message = expected;
|
469
615
|
expected = null;
|
@@ -481,28 +627,42 @@ QUnit.assert = {
|
|
481
627
|
// we don't want to validate thrown error
|
482
628
|
if ( !expected ) {
|
483
629
|
ok = true;
|
630
|
+
expectedOutput = null;
|
484
631
|
// expected is a regexp
|
485
632
|
} else if ( QUnit.objectType( expected ) === "regexp" ) {
|
486
|
-
ok = expected.test( actual );
|
633
|
+
ok = expected.test( errorString( actual ) );
|
487
634
|
// expected is a constructor
|
488
635
|
} else if ( actual instanceof expected ) {
|
489
636
|
ok = true;
|
490
637
|
// expected is a validation function which returns true is validation passed
|
491
638
|
} else if ( expected.call( {}, actual ) === true ) {
|
639
|
+
expectedOutput = null;
|
492
640
|
ok = true;
|
493
641
|
}
|
494
|
-
}
|
495
642
|
|
496
|
-
|
643
|
+
QUnit.push( ok, actual, expectedOutput, message );
|
644
|
+
} else {
|
645
|
+
QUnit.pushFailure( message, null, 'No exception was thrown.' );
|
646
|
+
}
|
497
647
|
}
|
498
648
|
};
|
499
649
|
|
500
|
-
|
501
|
-
|
650
|
+
/**
|
651
|
+
* @deprecate since 1.8.0
|
652
|
+
* Kept assertion helpers in root for backwards compatibility.
|
653
|
+
*/
|
654
|
+
extend( QUnit, assert );
|
655
|
+
|
656
|
+
/**
|
657
|
+
* @deprecated since 1.9.0
|
658
|
+
* Kept root "raises()" for backwards compatibility.
|
659
|
+
* (Note that we don't introduce assert.raises).
|
660
|
+
*/
|
661
|
+
QUnit.raises = assert[ "throws" ];
|
502
662
|
|
503
663
|
/**
|
504
|
-
* @deprecated
|
505
|
-
*
|
664
|
+
* @deprecated since 1.0.0, replaced with error pushes since 1.3.0
|
665
|
+
* Kept to avoid TypeErrors for undefined methods.
|
506
666
|
*/
|
507
667
|
QUnit.equals = function() {
|
508
668
|
QUnit.push( false, false, false, "QUnit.equals has been deprecated since 2009 (e88049a0), use QUnit.equal instead" );
|
@@ -546,7 +706,23 @@ config = {
|
|
546
706
|
// when enabled, all tests must call expect()
|
547
707
|
requireExpects: false,
|
548
708
|
|
549
|
-
|
709
|
+
// add checkboxes that are persisted in the query-string
|
710
|
+
// when enabled, the id is set to `true` as a `QUnit.config` property
|
711
|
+
urlConfig: [
|
712
|
+
{
|
713
|
+
id: "noglobals",
|
714
|
+
label: "Check for Globals",
|
715
|
+
tooltip: "Enabling this will test if any test introduces new properties on the `window` object. Stored as query-strings."
|
716
|
+
},
|
717
|
+
{
|
718
|
+
id: "notrycatch",
|
719
|
+
label: "No try-catch",
|
720
|
+
tooltip: "Enabling this will run tests outside of a try-catch block. Makes debugging exceptions in IE reasonable. Stored as query-strings."
|
721
|
+
}
|
722
|
+
],
|
723
|
+
|
724
|
+
// Set of all modules.
|
725
|
+
modules: {},
|
550
726
|
|
551
727
|
// logging callback queues
|
552
728
|
begin: [],
|
@@ -558,6 +734,15 @@ config = {
|
|
558
734
|
moduleDone: []
|
559
735
|
};
|
560
736
|
|
737
|
+
// Export global variables, unless an 'exports' object exists,
|
738
|
+
// in that case we assume we're in CommonJS (dealt with on the bottom of the script)
|
739
|
+
if ( typeof exports === "undefined" ) {
|
740
|
+
extend( window, QUnit );
|
741
|
+
|
742
|
+
// Expose QUnit object
|
743
|
+
window.QUnit = QUnit;
|
744
|
+
}
|
745
|
+
|
561
746
|
// Initialize more QUnit.config and QUnit.urlParams
|
562
747
|
(function() {
|
563
748
|
var i,
|
@@ -591,18 +776,11 @@ config = {
|
|
591
776
|
QUnit.isLocal = location.protocol === "file:";
|
592
777
|
}());
|
593
778
|
|
594
|
-
// Export global variables, unless an 'exports' object exists,
|
595
|
-
// in that case we assume we're in CommonJS (dealt with on the bottom of the script)
|
596
|
-
if ( typeof exports === "undefined" ) {
|
597
|
-
extend( window, QUnit );
|
598
|
-
|
599
|
-
// Expose QUnit object
|
600
|
-
window.QUnit = QUnit;
|
601
|
-
}
|
602
|
-
|
603
779
|
// Extend QUnit object,
|
604
780
|
// these after set here because they should not be exposed as global functions
|
605
781
|
extend( QUnit, {
|
782
|
+
assert: assert,
|
783
|
+
|
606
784
|
config: config,
|
607
785
|
|
608
786
|
// Initialize the configuration options
|
@@ -617,7 +795,7 @@ extend( QUnit, {
|
|
617
795
|
autorun: false,
|
618
796
|
filter: "",
|
619
797
|
queue: [],
|
620
|
-
semaphore:
|
798
|
+
semaphore: 1
|
621
799
|
});
|
622
800
|
|
623
801
|
var tests, banner, result,
|
@@ -625,7 +803,7 @@ extend( QUnit, {
|
|
625
803
|
|
626
804
|
if ( qunit ) {
|
627
805
|
qunit.innerHTML =
|
628
|
-
"<h1 id='qunit-header'>" +
|
806
|
+
"<h1 id='qunit-header'>" + escapeText( document.title ) + "</h1>" +
|
629
807
|
"<h2 id='qunit-banner'></h2>" +
|
630
808
|
"<div id='qunit-testrunner-toolbar'></div>" +
|
631
809
|
"<h2 id='qunit-userAgent'></h2>" +
|
@@ -658,17 +836,10 @@ extend( QUnit, {
|
|
658
836
|
},
|
659
837
|
|
660
838
|
// Resets the test setup. Useful for tests that modify the DOM.
|
661
|
-
// If jQuery is available, uses jQuery's html(), otherwise just innerHTML.
|
662
839
|
reset: function() {
|
663
|
-
var fixture;
|
664
|
-
|
665
|
-
|
666
|
-
jQuery( "#qunit-fixture" ).html( config.fixture );
|
667
|
-
} else {
|
668
|
-
fixture = id( "qunit-fixture" );
|
669
|
-
if ( fixture ) {
|
670
|
-
fixture.innerHTML = config.fixture;
|
671
|
-
}
|
840
|
+
var fixture = id( "qunit-fixture" );
|
841
|
+
if ( fixture ) {
|
842
|
+
fixture.innerHTML = config.fixture;
|
672
843
|
}
|
673
844
|
},
|
674
845
|
|
@@ -688,7 +859,7 @@ extend( QUnit, {
|
|
688
859
|
|
689
860
|
// Safe object type checking
|
690
861
|
is: function( type, obj ) {
|
691
|
-
return QUnit.objectType( obj )
|
862
|
+
return QUnit.objectType( obj ) === type;
|
692
863
|
},
|
693
864
|
|
694
865
|
objectType: function( obj ) {
|
@@ -700,7 +871,8 @@ extend( QUnit, {
|
|
700
871
|
return "null";
|
701
872
|
}
|
702
873
|
|
703
|
-
var
|
874
|
+
var match = toString.call( obj ).match(/^\[object\s(.*)\]$/),
|
875
|
+
type = match && match[1] || "";
|
704
876
|
|
705
877
|
switch ( type ) {
|
706
878
|
case "Number":
|
@@ -729,31 +901,33 @@ extend( QUnit, {
|
|
729
901
|
|
730
902
|
var output, source,
|
731
903
|
details = {
|
904
|
+
module: config.current.module,
|
905
|
+
name: config.current.testName,
|
732
906
|
result: result,
|
733
907
|
message: message,
|
734
908
|
actual: actual,
|
735
909
|
expected: expected
|
736
910
|
};
|
737
911
|
|
738
|
-
message =
|
912
|
+
message = escapeText( message ) || ( result ? "okay" : "failed" );
|
739
913
|
message = "<span class='test-message'>" + message + "</span>";
|
740
914
|
output = message;
|
741
915
|
|
742
916
|
if ( !result ) {
|
743
|
-
expected =
|
744
|
-
actual =
|
745
|
-
output += "<table><tr class='test-expected'><th>Expected: </th><td><
|
917
|
+
expected = escapeText( QUnit.jsDump.parse(expected) );
|
918
|
+
actual = escapeText( QUnit.jsDump.parse(actual) );
|
919
|
+
output += "<table><tr class='test-expected'><th>Expected: </th><td><pre>" + expected + "</pre></td></tr>";
|
746
920
|
|
747
|
-
if ( actual
|
748
|
-
output += "<tr class='test-actual'><th>Result: </th><td><
|
749
|
-
output += "<tr class='test-diff'><th>Diff: </th><td><
|
921
|
+
if ( actual !== expected ) {
|
922
|
+
output += "<tr class='test-actual'><th>Result: </th><td><pre>" + actual + "</pre></td></tr>";
|
923
|
+
output += "<tr class='test-diff'><th>Diff: </th><td><pre>" + QUnit.diff( expected, actual ) + "</pre></td></tr>";
|
750
924
|
}
|
751
925
|
|
752
926
|
source = sourceFromStacktrace();
|
753
927
|
|
754
928
|
if ( source ) {
|
755
929
|
details.source = source;
|
756
|
-
output += "<tr class='test-source'><th>Source: </th><td><
|
930
|
+
output += "<tr class='test-source'><th>Source: </th><td><pre>" + escapeText( source ) + "</pre></td></tr>";
|
757
931
|
}
|
758
932
|
|
759
933
|
output += "</table>";
|
@@ -767,22 +941,36 @@ extend( QUnit, {
|
|
767
941
|
});
|
768
942
|
},
|
769
943
|
|
770
|
-
pushFailure: function( message, source ) {
|
944
|
+
pushFailure: function( message, source, actual ) {
|
945
|
+
if ( !config.current ) {
|
946
|
+
throw new Error( "pushFailure() assertion outside test context, was " + sourceFromStacktrace(2) );
|
947
|
+
}
|
948
|
+
|
771
949
|
var output,
|
772
950
|
details = {
|
951
|
+
module: config.current.module,
|
952
|
+
name: config.current.testName,
|
773
953
|
result: false,
|
774
954
|
message: message
|
775
955
|
};
|
776
956
|
|
777
|
-
message =
|
957
|
+
message = escapeText( message ) || "error";
|
778
958
|
message = "<span class='test-message'>" + message + "</span>";
|
779
959
|
output = message;
|
780
960
|
|
961
|
+
output += "<table>";
|
962
|
+
|
963
|
+
if ( actual ) {
|
964
|
+
output += "<tr class='test-actual'><th>Result: </th><td><pre>" + escapeText( actual ) + "</pre></td></tr>";
|
965
|
+
}
|
966
|
+
|
781
967
|
if ( source ) {
|
782
968
|
details.source = source;
|
783
|
-
output += "<
|
969
|
+
output += "<tr class='test-source'><th>Source: </th><td><pre>" + escapeText( source ) + "</pre></td></tr>";
|
784
970
|
}
|
785
971
|
|
972
|
+
output += "</table>";
|
973
|
+
|
786
974
|
runLoggingCallbacks( "log", QUnit, details );
|
787
975
|
|
788
976
|
config.current.assertions.push({
|
@@ -803,7 +991,8 @@ extend( QUnit, {
|
|
803
991
|
querystring += encodeURIComponent( key ) + "=" +
|
804
992
|
encodeURIComponent( params[ key ] ) + "&";
|
805
993
|
}
|
806
|
-
return window.location.
|
994
|
+
return window.location.protocol + "//" + window.location.host +
|
995
|
+
window.location.pathname + querystring.slice( 0, -1 );
|
807
996
|
},
|
808
997
|
|
809
998
|
extend: extend,
|
@@ -834,7 +1023,7 @@ extend( QUnit.constructor.prototype, {
|
|
834
1023
|
// testStart: { name }
|
835
1024
|
testStart: registerLoggingCallback( "testStart" ),
|
836
1025
|
|
837
|
-
// testDone: { name, failed, passed, total }
|
1026
|
+
// testDone: { name, failed, passed, total, duration }
|
838
1027
|
testDone: registerLoggingCallback( "testDone" ),
|
839
1028
|
|
840
1029
|
// moduleStart: { name }
|
@@ -853,6 +1042,9 @@ QUnit.load = function() {
|
|
853
1042
|
|
854
1043
|
// Initialize the config, saving the execution queue
|
855
1044
|
var banner, filter, i, label, len, main, ol, toolbar, userAgent, val,
|
1045
|
+
urlConfigCheckboxesContainer, urlConfigCheckboxes, moduleFilter,
|
1046
|
+
numModules = 0,
|
1047
|
+
moduleFilterHtml = "",
|
856
1048
|
urlConfigHtml = "",
|
857
1049
|
oldconfig = extend( {}, config );
|
858
1050
|
|
@@ -865,9 +1057,35 @@ QUnit.load = function() {
|
|
865
1057
|
|
866
1058
|
for ( i = 0; i < len; i++ ) {
|
867
1059
|
val = config.urlConfig[i];
|
868
|
-
|
869
|
-
|
1060
|
+
if ( typeof val === "string" ) {
|
1061
|
+
val = {
|
1062
|
+
id: val,
|
1063
|
+
label: val,
|
1064
|
+
tooltip: "[no tooltip available]"
|
1065
|
+
};
|
1066
|
+
}
|
1067
|
+
config[ val.id ] = QUnit.urlParams[ val.id ];
|
1068
|
+
urlConfigHtml += "<input id='qunit-urlconfig-" + escapeText( val.id ) +
|
1069
|
+
"' name='" + escapeText( val.id ) +
|
1070
|
+
"' type='checkbox'" + ( config[ val.id ] ? " checked='checked'" : "" ) +
|
1071
|
+
" title='" + escapeText( val.tooltip ) +
|
1072
|
+
"'><label for='qunit-urlconfig-" + escapeText( val.id ) +
|
1073
|
+
"' title='" + escapeText( val.tooltip ) + "'>" + val.label + "</label>";
|
1074
|
+
}
|
1075
|
+
|
1076
|
+
moduleFilterHtml += "<label for='qunit-modulefilter'>Module: </label><select id='qunit-modulefilter' name='modulefilter'><option value='' " +
|
1077
|
+
( config.module === undefined ? "selected='selected'" : "" ) +
|
1078
|
+
">< All Modules ></option>";
|
1079
|
+
|
1080
|
+
for ( i in config.modules ) {
|
1081
|
+
if ( config.modules.hasOwnProperty( i ) ) {
|
1082
|
+
numModules += 1;
|
1083
|
+
moduleFilterHtml += "<option value='" + escapeText( encodeURIComponent(i) ) + "' " +
|
1084
|
+
( config.module === i ? "selected='selected'" : "" ) +
|
1085
|
+
">" + escapeText(i) + "</option>";
|
1086
|
+
}
|
870
1087
|
}
|
1088
|
+
moduleFilterHtml += "</select>";
|
871
1089
|
|
872
1090
|
// `userAgent` initialized at top of scope
|
873
1091
|
userAgent = id( "qunit-userAgent" );
|
@@ -878,12 +1096,7 @@ QUnit.load = function() {
|
|
878
1096
|
// `banner` initialized at top of scope
|
879
1097
|
banner = id( "qunit-header" );
|
880
1098
|
if ( banner ) {
|
881
|
-
banner.innerHTML = "<a href='" + QUnit.url({ filter: undefined }) + "'>" + banner.innerHTML + "</a> "
|
882
|
-
addEvent( banner, "change", function( event ) {
|
883
|
-
var params = {};
|
884
|
-
params[ event.target.name ] = event.target.checked ? true : undefined;
|
885
|
-
window.location = QUnit.url( params );
|
886
|
-
});
|
1099
|
+
banner.innerHTML = "<a href='" + QUnit.url({ filter: undefined, module: undefined, testNumber: undefined }) + "'>" + banner.innerHTML + "</a> ";
|
887
1100
|
}
|
888
1101
|
|
889
1102
|
// `toolbar` initialized at top of scope
|
@@ -924,8 +1137,37 @@ QUnit.load = function() {
|
|
924
1137
|
// `label` initialized at top of scope
|
925
1138
|
label = document.createElement( "label" );
|
926
1139
|
label.setAttribute( "for", "qunit-filter-pass" );
|
1140
|
+
label.setAttribute( "title", "Only show tests and assertons that fail. Stored in sessionStorage." );
|
927
1141
|
label.innerHTML = "Hide passed tests";
|
928
1142
|
toolbar.appendChild( label );
|
1143
|
+
|
1144
|
+
urlConfigCheckboxesContainer = document.createElement("span");
|
1145
|
+
urlConfigCheckboxesContainer.innerHTML = urlConfigHtml;
|
1146
|
+
urlConfigCheckboxes = urlConfigCheckboxesContainer.getElementsByTagName("input");
|
1147
|
+
// For oldIE support:
|
1148
|
+
// * Add handlers to the individual elements instead of the container
|
1149
|
+
// * Use "click" instead of "change"
|
1150
|
+
// * Fallback from event.target to event.srcElement
|
1151
|
+
addEvents( urlConfigCheckboxes, "click", function( event ) {
|
1152
|
+
var params = {},
|
1153
|
+
target = event.target || event.srcElement;
|
1154
|
+
params[ target.name ] = target.checked ? true : undefined;
|
1155
|
+
window.location = QUnit.url( params );
|
1156
|
+
});
|
1157
|
+
toolbar.appendChild( urlConfigCheckboxesContainer );
|
1158
|
+
|
1159
|
+
if (numModules > 1) {
|
1160
|
+
moduleFilter = document.createElement( 'span' );
|
1161
|
+
moduleFilter.setAttribute( 'id', 'qunit-modulefilter-container' );
|
1162
|
+
moduleFilter.innerHTML = moduleFilterHtml;
|
1163
|
+
addEvent( moduleFilter.lastChild, "change", function() {
|
1164
|
+
var selectBox = moduleFilter.getElementsByTagName("select")[0],
|
1165
|
+
selectedModule = decodeURIComponent(selectBox.options[selectBox.selectedIndex].value);
|
1166
|
+
|
1167
|
+
window.location = QUnit.url( { module: ( selectedModule === "" ) ? undefined : selectedModule } );
|
1168
|
+
});
|
1169
|
+
toolbar.appendChild(moduleFilter);
|
1170
|
+
}
|
929
1171
|
}
|
930
1172
|
|
931
1173
|
// `main` initialized at top of scope
|
@@ -941,18 +1183,36 @@ QUnit.load = function() {
|
|
941
1183
|
|
942
1184
|
addEvent( window, "load", QUnit.load );
|
943
1185
|
|
944
|
-
//
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
1186
|
+
// `onErrorFnPrev` initialized at top of scope
|
1187
|
+
// Preserve other handlers
|
1188
|
+
onErrorFnPrev = window.onerror;
|
1189
|
+
|
1190
|
+
// Cover uncaught exceptions
|
1191
|
+
// Returning true will surpress the default browser handler,
|
1192
|
+
// returning false will let it run.
|
1193
|
+
window.onerror = function ( error, filePath, linerNr ) {
|
1194
|
+
var ret = false;
|
1195
|
+
if ( onErrorFnPrev ) {
|
1196
|
+
ret = onErrorFnPrev( error, filePath, linerNr );
|
1197
|
+
}
|
1198
|
+
|
1199
|
+
// Treat return value as window.onerror itself does,
|
1200
|
+
// Only do our handling if not surpressed.
|
1201
|
+
if ( ret !== true ) {
|
1202
|
+
if ( QUnit.config.current ) {
|
1203
|
+
if ( QUnit.config.current.ignoreGlobalErrors ) {
|
1204
|
+
return true;
|
1205
|
+
}
|
1206
|
+
QUnit.pushFailure( error, filePath + ":" + linerNr );
|
1207
|
+
} else {
|
1208
|
+
QUnit.test( "global failure", extend( function() {
|
1209
|
+
QUnit.pushFailure( error, filePath + ":" + linerNr );
|
1210
|
+
}, { validTest: validTest } ) );
|
949
1211
|
}
|
950
|
-
|
951
|
-
} else {
|
952
|
-
QUnit.test( "global failure", function() {
|
953
|
-
QUnit.pushFailure( message, file + ":" + line );
|
954
|
-
});
|
1212
|
+
return false;
|
955
1213
|
}
|
1214
|
+
|
1215
|
+
return ret;
|
956
1216
|
};
|
957
1217
|
|
958
1218
|
function done() {
|
@@ -979,7 +1239,7 @@ function done() {
|
|
979
1239
|
" milliseconds.<br/>",
|
980
1240
|
"<span class='passed'>",
|
981
1241
|
passed,
|
982
|
-
"</span>
|
1242
|
+
"</span> assertions of <span class='total'>",
|
983
1243
|
config.stats.all,
|
984
1244
|
"</span> passed, <span class='failed'>",
|
985
1245
|
config.stats.bad,
|
@@ -1014,6 +1274,11 @@ function done() {
|
|
1014
1274
|
}
|
1015
1275
|
}
|
1016
1276
|
|
1277
|
+
// scroll back to top to show results
|
1278
|
+
if ( window.scrollTo ) {
|
1279
|
+
window.scrollTo(0, 0);
|
1280
|
+
}
|
1281
|
+
|
1017
1282
|
runLoggingCallbacks( "done", QUnit, {
|
1018
1283
|
failed: config.stats.bad,
|
1019
1284
|
passed: passed,
|
@@ -1026,14 +1291,20 @@ function done() {
|
|
1026
1291
|
function validTest( test ) {
|
1027
1292
|
var include,
|
1028
1293
|
filter = config.filter && config.filter.toLowerCase(),
|
1029
|
-
module = config.module,
|
1294
|
+
module = config.module && config.module.toLowerCase(),
|
1030
1295
|
fullName = (test.module + ": " + test.testName).toLowerCase();
|
1031
1296
|
|
1297
|
+
// Internally-generated tests are always valid
|
1298
|
+
if ( test.callback && test.callback.validTest === validTest ) {
|
1299
|
+
delete test.callback.validTest;
|
1300
|
+
return true;
|
1301
|
+
}
|
1302
|
+
|
1032
1303
|
if ( config.testNumber ) {
|
1033
1304
|
return test.testNumber === config.testNumber;
|
1034
1305
|
}
|
1035
1306
|
|
1036
|
-
if ( module && test.module !== module ) {
|
1307
|
+
if ( module && ( !test.module || test.module.toLowerCase() !== module ) ) {
|
1037
1308
|
return false;
|
1038
1309
|
}
|
1039
1310
|
|
@@ -1061,7 +1332,7 @@ function validTest( test ) {
|
|
1061
1332
|
function extractStacktrace( e, offset ) {
|
1062
1333
|
offset = offset === undefined ? 3 : offset;
|
1063
1334
|
|
1064
|
-
var stack, include, i
|
1335
|
+
var stack, include, i;
|
1065
1336
|
|
1066
1337
|
if ( e.stacktrace ) {
|
1067
1338
|
// Opera
|
@@ -1075,7 +1346,7 @@ function extractStacktrace( e, offset ) {
|
|
1075
1346
|
if ( fileName ) {
|
1076
1347
|
include = [];
|
1077
1348
|
for ( i = offset; i < stack.length; i++ ) {
|
1078
|
-
if ( stack[ i ].indexOf( fileName )
|
1349
|
+
if ( stack[ i ].indexOf( fileName ) !== -1 ) {
|
1079
1350
|
break;
|
1080
1351
|
}
|
1081
1352
|
include.push( stack[ i ] );
|
@@ -1104,17 +1375,27 @@ function sourceFromStacktrace( offset ) {
|
|
1104
1375
|
}
|
1105
1376
|
}
|
1106
1377
|
|
1107
|
-
|
1378
|
+
/**
|
1379
|
+
* Escape text for attribute or text content.
|
1380
|
+
*/
|
1381
|
+
function escapeText( s ) {
|
1108
1382
|
if ( !s ) {
|
1109
1383
|
return "";
|
1110
1384
|
}
|
1111
1385
|
s = s + "";
|
1112
|
-
|
1386
|
+
// Both single quotes and double quotes (for attributes)
|
1387
|
+
return s.replace( /['"<>&]/g, function( s ) {
|
1113
1388
|
switch( s ) {
|
1114
|
-
case
|
1115
|
-
|
1116
|
-
case "
|
1117
|
-
|
1389
|
+
case '\'':
|
1390
|
+
return ''';
|
1391
|
+
case '"':
|
1392
|
+
return '"';
|
1393
|
+
case '<':
|
1394
|
+
return '<';
|
1395
|
+
case '>':
|
1396
|
+
return '>';
|
1397
|
+
case '&':
|
1398
|
+
return '&';
|
1118
1399
|
}
|
1119
1400
|
});
|
1120
1401
|
}
|
@@ -1162,7 +1443,7 @@ function saveGlobal() {
|
|
1162
1443
|
}
|
1163
1444
|
}
|
1164
1445
|
|
1165
|
-
function checkPollution(
|
1446
|
+
function checkPollution() {
|
1166
1447
|
var newGlobals,
|
1167
1448
|
deletedGlobals,
|
1168
1449
|
old = config.pollution;
|
@@ -1211,16 +1492,53 @@ function extend( a, b ) {
|
|
1211
1492
|
return a;
|
1212
1493
|
}
|
1213
1494
|
|
1495
|
+
/**
|
1496
|
+
* @param {HTMLElement} elem
|
1497
|
+
* @param {string} type
|
1498
|
+
* @param {Function} fn
|
1499
|
+
*/
|
1214
1500
|
function addEvent( elem, type, fn ) {
|
1501
|
+
// Standards-based browsers
|
1215
1502
|
if ( elem.addEventListener ) {
|
1216
1503
|
elem.addEventListener( type, fn, false );
|
1217
|
-
|
1218
|
-
elem.attachEvent( "on" + type, fn );
|
1504
|
+
// IE
|
1219
1505
|
} else {
|
1220
|
-
fn
|
1506
|
+
elem.attachEvent( "on" + type, fn );
|
1507
|
+
}
|
1508
|
+
}
|
1509
|
+
|
1510
|
+
/**
|
1511
|
+
* @param {Array|NodeList} elems
|
1512
|
+
* @param {string} type
|
1513
|
+
* @param {Function} fn
|
1514
|
+
*/
|
1515
|
+
function addEvents( elems, type, fn ) {
|
1516
|
+
var i = elems.length;
|
1517
|
+
while ( i-- ) {
|
1518
|
+
addEvent( elems[i], type, fn );
|
1519
|
+
}
|
1520
|
+
}
|
1521
|
+
|
1522
|
+
function hasClass( elem, name ) {
|
1523
|
+
return (" " + elem.className + " ").indexOf(" " + name + " ") > -1;
|
1524
|
+
}
|
1525
|
+
|
1526
|
+
function addClass( elem, name ) {
|
1527
|
+
if ( !hasClass( elem, name ) ) {
|
1528
|
+
elem.className += (elem.className ? " " : "") + name;
|
1221
1529
|
}
|
1222
1530
|
}
|
1223
1531
|
|
1532
|
+
function removeClass( elem, name ) {
|
1533
|
+
var set = " " + elem.className + " ";
|
1534
|
+
// Class name may appear multiple times
|
1535
|
+
while ( set.indexOf(" " + name + " ") > -1 ) {
|
1536
|
+
set = set.replace(" " + name + " " , " ");
|
1537
|
+
}
|
1538
|
+
// If possible, trim it for prettiness, but not neccecarily
|
1539
|
+
elem.className = window.jQuery ? jQuery.trim( set ) : ( set.trim ? set.trim() : set );
|
1540
|
+
}
|
1541
|
+
|
1224
1542
|
function id( name ) {
|
1225
1543
|
return !!( typeof document !== "undefined" && document && document.getElementById ) &&
|
1226
1544
|
document.getElementById( name );
|
@@ -1234,7 +1552,6 @@ function registerLoggingCallback( key ) {
|
|
1234
1552
|
|
1235
1553
|
// Supports deprecated method of completely overwriting logging callbacks
|
1236
1554
|
function runLoggingCallbacks( key, scope, args ) {
|
1237
|
-
//debugger;
|
1238
1555
|
var i, callbacks;
|
1239
1556
|
if ( QUnit.hasOwnProperty( key ) ) {
|
1240
1557
|
QUnit[ key ].call(scope, args );
|
@@ -1276,6 +1593,7 @@ QUnit.equiv = (function() {
|
|
1276
1593
|
|
1277
1594
|
// for string, boolean, number and null
|
1278
1595
|
function useStrictEquality( b, a ) {
|
1596
|
+
/*jshint eqeqeq:false */
|
1279
1597
|
if ( b instanceof a.constructor || a instanceof b.constructor ) {
|
1280
1598
|
// to catch short annotaion VS 'new' annotation of a
|
1281
1599
|
// declaration
|
@@ -1310,7 +1628,8 @@ QUnit.equiv = (function() {
|
|
1310
1628
|
a.global === b.global &&
|
1311
1629
|
// (gmi) ...
|
1312
1630
|
a.ignoreCase === b.ignoreCase &&
|
1313
|
-
a.multiline === b.multiline
|
1631
|
+
a.multiline === b.multiline &&
|
1632
|
+
a.sticky === b.sticky;
|
1314
1633
|
},
|
1315
1634
|
|
1316
1635
|
// - skip when the property is a method of an instance (OOP)
|
@@ -1471,7 +1790,8 @@ QUnit.jsDump = (function() {
|
|
1471
1790
|
|
1472
1791
|
var reName = /^function (\w+)/,
|
1473
1792
|
jsDump = {
|
1474
|
-
|
1793
|
+
// type is used mostly internally, you can fix a (custom)type in advance
|
1794
|
+
parse: function( obj, type, stack ) {
|
1475
1795
|
stack = stack || [ ];
|
1476
1796
|
var inStack, res,
|
1477
1797
|
parser = this.parsers[ type || this.typeOf(obj) ];
|
@@ -1479,18 +1799,16 @@ QUnit.jsDump = (function() {
|
|
1479
1799
|
type = typeof parser;
|
1480
1800
|
inStack = inArray( obj, stack );
|
1481
1801
|
|
1482
|
-
if ( inStack
|
1802
|
+
if ( inStack !== -1 ) {
|
1483
1803
|
return "recursion(" + (inStack - stack.length) + ")";
|
1484
1804
|
}
|
1485
|
-
|
1486
|
-
if ( type == "function" ) {
|
1805
|
+
if ( type === "function" ) {
|
1487
1806
|
stack.push( obj );
|
1488
1807
|
res = parser.call( this, obj, stack );
|
1489
1808
|
stack.pop();
|
1490
1809
|
return res;
|
1491
1810
|
}
|
1492
|
-
|
1493
|
-
return ( type == "string" ) ? parser : this.parsers.error;
|
1811
|
+
return ( type === "string" ) ? parser : this.parsers.error;
|
1494
1812
|
},
|
1495
1813
|
typeOf: function( obj ) {
|
1496
1814
|
var type;
|
@@ -1517,6 +1835,8 @@ QUnit.jsDump = (function() {
|
|
1517
1835
|
( typeof obj.length === "number" && typeof obj.item !== "undefined" && ( obj.length ? obj.item(0) === obj[0] : ( obj.item( 0 ) === null && typeof obj[0] === "undefined" ) ) )
|
1518
1836
|
) {
|
1519
1837
|
type = "array";
|
1838
|
+
} else if ( obj.constructor === Error.prototype.constructor ) {
|
1839
|
+
type = "error";
|
1520
1840
|
} else {
|
1521
1841
|
type = typeof obj;
|
1522
1842
|
}
|
@@ -1525,7 +1845,8 @@ QUnit.jsDump = (function() {
|
|
1525
1845
|
separator: function() {
|
1526
1846
|
return this.multiline ? this.HTML ? "<br />" : "\n" : this.HTML ? " " : " ";
|
1527
1847
|
},
|
1528
|
-
|
1848
|
+
// extra can be a number, shortcut for increasing-calling-decreasing
|
1849
|
+
indent: function( extra ) {
|
1529
1850
|
if ( !this.multiline ) {
|
1530
1851
|
return "";
|
1531
1852
|
}
|
@@ -1554,13 +1875,16 @@ QUnit.jsDump = (function() {
|
|
1554
1875
|
parsers: {
|
1555
1876
|
window: "[Window]",
|
1556
1877
|
document: "[Document]",
|
1557
|
-
error:
|
1878
|
+
error: function(error) {
|
1879
|
+
return "Error(\"" + error.message + "\")";
|
1880
|
+
},
|
1558
1881
|
unknown: "[Unknown]",
|
1559
1882
|
"null": "null",
|
1560
1883
|
"undefined": "undefined",
|
1561
1884
|
"function": function( fn ) {
|
1562
1885
|
var ret = "function",
|
1563
|
-
|
1886
|
+
// functions never have name in IE
|
1887
|
+
name = "name" in fn ? fn.name : (reName.exec(fn) || [])[1];
|
1564
1888
|
|
1565
1889
|
if ( name ) {
|
1566
1890
|
ret += " " + name;
|
@@ -1576,13 +1900,9 @@ QUnit.jsDump = (function() {
|
|
1576
1900
|
object: function( map, stack ) {
|
1577
1901
|
var ret = [ ], keys, key, val, i;
|
1578
1902
|
QUnit.jsDump.up();
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
1582
|
-
keys = [];
|
1583
|
-
for ( key in map ) {
|
1584
|
-
keys.push( key );
|
1585
|
-
}
|
1903
|
+
keys = [];
|
1904
|
+
for ( key in map ) {
|
1905
|
+
keys.push( key );
|
1586
1906
|
}
|
1587
1907
|
keys.sort();
|
1588
1908
|
for ( i = 0; i < keys.length; i++ ) {
|
@@ -1594,21 +1914,34 @@ QUnit.jsDump = (function() {
|
|
1594
1914
|
return join( "{", ret, "}" );
|
1595
1915
|
},
|
1596
1916
|
node: function( node ) {
|
1597
|
-
var
|
1917
|
+
var len, i, val,
|
1598
1918
|
open = QUnit.jsDump.HTML ? "<" : "<",
|
1599
1919
|
close = QUnit.jsDump.HTML ? ">" : ">",
|
1600
1920
|
tag = node.nodeName.toLowerCase(),
|
1601
|
-
ret = open + tag
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1921
|
+
ret = open + tag,
|
1922
|
+
attrs = node.attributes;
|
1923
|
+
|
1924
|
+
if ( attrs ) {
|
1925
|
+
for ( i = 0, len = attrs.length; i < len; i++ ) {
|
1926
|
+
val = attrs[i].nodeValue;
|
1927
|
+
// IE6 includes all attributes in .attributes, even ones not explicitly set.
|
1928
|
+
// Those have values like undefined, null, 0, false, "" or "inherit".
|
1929
|
+
if ( val && val !== "inherit" ) {
|
1930
|
+
ret += " " + attrs[i].nodeName + "=" + QUnit.jsDump.parse( val, "attribute" );
|
1931
|
+
}
|
1607
1932
|
}
|
1608
1933
|
}
|
1609
|
-
|
1934
|
+
ret += close;
|
1935
|
+
|
1936
|
+
// Show content of TextNode or CDATASection
|
1937
|
+
if ( node.nodeType === 3 || node.nodeType === 4 ) {
|
1938
|
+
ret += node.nodeValue;
|
1939
|
+
}
|
1940
|
+
|
1941
|
+
return ret + open + "/" + tag + close;
|
1610
1942
|
},
|
1611
|
-
|
1943
|
+
// function calls it internally, it's the arguments part of the function
|
1944
|
+
functionArgs: function( fn ) {
|
1612
1945
|
var args,
|
1613
1946
|
l = fn.length;
|
1614
1947
|
|
@@ -1618,54 +1951,34 @@ QUnit.jsDump = (function() {
|
|
1618
1951
|
|
1619
1952
|
args = new Array(l);
|
1620
1953
|
while ( l-- ) {
|
1621
|
-
|
1954
|
+
// 97 is 'a'
|
1955
|
+
args[l] = String.fromCharCode(97+l);
|
1622
1956
|
}
|
1623
1957
|
return " " + args.join( ", " ) + " ";
|
1624
1958
|
},
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1959
|
+
// object calls it internally, the key part of an item in a map
|
1960
|
+
key: quote,
|
1961
|
+
// function calls it internally, it's the content of the function
|
1962
|
+
functionCode: "[code]",
|
1963
|
+
// node calls it internally, it's an html attribute value
|
1964
|
+
attribute: quote,
|
1628
1965
|
string: quote,
|
1629
1966
|
date: quote,
|
1630
|
-
regexp: literal,
|
1967
|
+
regexp: literal,
|
1631
1968
|
number: literal,
|
1632
1969
|
"boolean": literal
|
1633
1970
|
},
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
HTML: false,//if true, entities are escaped ( <, >, \t, space and \n )
|
1641
|
-
indentChar: " ",//indentation unit
|
1642
|
-
multiline: true //if true, items in a collection, are separated by a \n, else just a space.
|
1971
|
+
// if true, entities are escaped ( <, >, \t, space and \n )
|
1972
|
+
HTML: false,
|
1973
|
+
// indentation unit
|
1974
|
+
indentChar: " ",
|
1975
|
+
// if true, items in a collection, are separated by a \n, else just a space.
|
1976
|
+
multiline: true
|
1643
1977
|
};
|
1644
1978
|
|
1645
1979
|
return jsDump;
|
1646
1980
|
}());
|
1647
1981
|
|
1648
|
-
// from Sizzle.js
|
1649
|
-
function getText( elems ) {
|
1650
|
-
var i, elem,
|
1651
|
-
ret = "";
|
1652
|
-
|
1653
|
-
for ( i = 0; elems[i]; i++ ) {
|
1654
|
-
elem = elems[i];
|
1655
|
-
|
1656
|
-
// Get the text from text nodes and CDATA nodes
|
1657
|
-
if ( elem.nodeType === 3 || elem.nodeType === 4 ) {
|
1658
|
-
ret += elem.nodeValue;
|
1659
|
-
|
1660
|
-
// Traverse everything else, except comment nodes
|
1661
|
-
} else if ( elem.nodeType !== 8 ) {
|
1662
|
-
ret += getText( elem.childNodes );
|
1663
|
-
}
|
1664
|
-
}
|
1665
|
-
|
1666
|
-
return ret;
|
1667
|
-
}
|
1668
|
-
|
1669
1982
|
// from jquery.js
|
1670
1983
|
function inArray( elem, array ) {
|
1671
1984
|
if ( array.indexOf ) {
|
@@ -1696,13 +2009,14 @@ function inArray( elem, array ) {
|
|
1696
2009
|
* QUnit.diff( "the quick brown fox jumped over", "the quick fox jumps over" ) == "the quick <del>brown </del> fox <del>jumped </del><ins>jumps </ins> over"
|
1697
2010
|
*/
|
1698
2011
|
QUnit.diff = (function() {
|
2012
|
+
/*jshint eqeqeq:false, eqnull:true */
|
1699
2013
|
function diff( o, n ) {
|
1700
2014
|
var i,
|
1701
2015
|
ns = {},
|
1702
2016
|
os = {};
|
1703
2017
|
|
1704
2018
|
for ( i = 0; i < n.length; i++ ) {
|
1705
|
-
if ( ns
|
2019
|
+
if ( !hasOwn.call( ns, n[i] ) ) {
|
1706
2020
|
ns[ n[i] ] = {
|
1707
2021
|
rows: [],
|
1708
2022
|
o: null
|
@@ -1712,7 +2026,7 @@ QUnit.diff = (function() {
|
|
1712
2026
|
}
|
1713
2027
|
|
1714
2028
|
for ( i = 0; i < o.length; i++ ) {
|
1715
|
-
if ( os
|
2029
|
+
if ( !hasOwn.call( os, o[i] ) ) {
|
1716
2030
|
os[ o[i] ] = {
|
1717
2031
|
rows: [],
|
1718
2032
|
n: null
|
@@ -1725,7 +2039,7 @@ QUnit.diff = (function() {
|
|
1725
2039
|
if ( !hasOwn.call( ns, i ) ) {
|
1726
2040
|
continue;
|
1727
2041
|
}
|
1728
|
-
if ( ns[i].rows.length
|
2042
|
+
if ( ns[i].rows.length === 1 && hasOwn.call( os, i ) && os[i].rows.length === 1 ) {
|
1729
2043
|
n[ ns[i].rows[0] ] = {
|
1730
2044
|
text: n[ ns[i].rows[0] ],
|
1731
2045
|
row: os[i].rows[0]
|
@@ -1831,7 +2145,7 @@ QUnit.diff = (function() {
|
|
1831
2145
|
|
1832
2146
|
// for CommonJS enviroments, export everything
|
1833
2147
|
if ( typeof exports !== "undefined" ) {
|
1834
|
-
extend(exports, QUnit);
|
2148
|
+
extend( exports, QUnit );
|
1835
2149
|
}
|
1836
2150
|
|
1837
2151
|
// get at whatever the global object is, like window in browsers
|