|
4 | 4 | * Based on a gist by Jörn Zaefferer <https://gist.github.com/722381>
|
5 | 5 | * Available under MIT license <http://mths.be/mit>
|
6 | 6 | */
|
7 |
| -;(function(root, undefined) { |
8 |
| - 'use strict'; |
| 7 | +;(function() { |
| 8 | + |
| 9 | + /** Used as a safe reference for `undefined` in pre ES5 environments */ |
| 10 | + var undefined; |
| 11 | + |
| 12 | + /** Used as a horizontal rule in console output */ |
| 13 | + var hr = '----------------------------------------'; |
9 | 14 |
|
10 | 15 | /** Native method shortcut */
|
11 | 16 | var unshift = Array.prototype.unshift;
|
|
27 | 32 | ''': "'"
|
28 | 33 | };
|
29 | 34 |
|
30 |
| - /** Used as a horizontal rule in console output */ |
31 |
| - var hr = '----------------------------------------'; |
| 35 | + /** Used to determine if values are of the language type Object */ |
| 36 | + var objectTypes = { |
| 37 | + 'function': true, |
| 38 | + 'object': true |
| 39 | + }; |
| 40 | + |
| 41 | + /** Used as a reference to the global object */ |
| 42 | + var root = (objectTypes[typeof window] && window) || this; |
32 | 43 |
|
33 | 44 | /** Detect free variable `exports` */
|
34 |
| - var freeExports = typeof exports == 'object' && exports; |
| 45 | + var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports; |
35 | 46 |
|
36 |
| - /** Detect free variable `global`, from Node.js or Browserified code, and use it as `root` */ |
37 |
| - var freeGlobal = typeof global == 'object' && global; |
38 |
| - if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) { |
| 47 | + /** Detect free variable `global` from Node.js or Browserified code and use it as `root` */ |
| 48 | + var freeGlobal = objectTypes[typeof global] && global; |
| 49 | + if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) { |
39 | 50 | root = freeGlobal;
|
40 | 51 | }
|
41 | 52 |
|
|
155 | 166 | * @param {number} delay The number of milliseconds to delay the `fn` call.
|
156 | 167 | * @param [arg1, arg2, ...] Arguments to invoke `fn` with.
|
157 | 168 | * @param {boolean} repeated A flag to specify whether `fn` is called repeatedly.
|
158 |
| - * @returns {number} The the ID of the timeout. |
| 169 | + * @returns {number} The ID of the timeout. |
159 | 170 | */
|
160 | 171 | function schedule(fn, delay, args, repeated) {
|
161 | 172 | // Rhino 1.7RC4 will error assigning `task` below
|
|
204 | 215 | * @param {Function|string} fn The function to call or string to evaluate.
|
205 | 216 | * @param {number} delay The number of milliseconds to delay each `fn` call.
|
206 | 217 | * @param [arg1, arg2, ...] Arguments to invoke `fn` with.
|
207 |
| - * @returns {number} The the ID of the timeout. |
| 218 | + * @returns {number} The ID of the timeout. |
208 | 219 | */
|
209 | 220 | function setInterval(fn, delay) {
|
210 | 221 | return schedule(fn, delay, slice.call(arguments, 2), true);
|
|
217 | 228 | * @param {Function|string} fn The function to call or string to evaluate.
|
218 | 229 | * @param {number} delay The number of milliseconds to delay the `fn` call.
|
219 | 230 | * @param [arg1, arg2, ...] Arguments to invoke `fn` with.
|
220 |
| - * @returns {number} The the ID of the timeout. |
| 231 | + * @returns {number} The ID of the timeout. |
221 | 232 | */
|
222 | 233 | function setTimeout(fn, delay) {
|
223 | 234 | return schedule(fn, delay, slice.call(arguments, 2));
|
|
282 | 293 | QUnit.config.excused = {};
|
283 | 294 |
|
284 | 295 | /**
|
285 |
| - * An object used to hold information about the current running test. |
| 296 | + * An object used to hold "extras" information about the current running test. |
286 | 297 | *
|
287 | 298 | * @memberOf QUnit.config
|
288 | 299 | * @type Object
|
289 | 300 | */
|
290 |
| - QUnit.config.testStats = { |
| 301 | + QUnit.config.extrasData = { |
291 | 302 |
|
292 | 303 | /**
|
293 |
| - * An array of test summaries. |
| 304 | + * An array of assertion logs. |
294 | 305 | *
|
295 |
| - * @memberOf QUnit.config.testStats |
| 306 | + * @memberOf QUnit.config.extrasData |
296 | 307 | * @type Array
|
297 | 308 | */
|
298 |
| - 'assertions': [] |
| 309 | + 'logs': [] |
299 | 310 | };
|
300 | 311 |
|
301 | 312 | /**
|
|
317 | 328 | test.retries = 0;
|
318 | 329 | test.finish = function() {
|
319 | 330 | var asserts = this.assertions,
|
| 331 | + config = QUnit.config, |
320 | 332 | index = -1,
|
321 | 333 | length = asserts.length,
|
322 |
| - queue = QUnit.config.queue; |
| 334 | + logs = config.extrasData.logs, |
| 335 | + queue = config.queue; |
323 | 336 |
|
324 | 337 | while (++index < length) {
|
325 | 338 | var assert = asserts[index];
|
326 |
| - if (!assert.result && this.retries < QUnit.config.asyncRetries) { |
| 339 | + if (!assert.result && this.retries < config.asyncRetries) { |
327 | 340 | this.retries++;
|
| 341 | + logs.length = Math.max(0, logs.length - asserts.length); |
328 | 342 | asserts.length = 0;
|
329 | 343 |
|
330 | 344 | var oldLength = queue.length;
|
|
430 | 444 | result = details.result,
|
431 | 445 | type = typeof expected != 'undefined' ? 'EQ' : 'OK';
|
432 | 446 |
|
433 |
| - var assertion = [ |
| 447 | + var message = [ |
434 | 448 | result ? 'PASS' : 'FAIL',
|
435 | 449 | type,
|
436 | 450 | details.message || 'ok'
|
437 | 451 | ];
|
438 | 452 |
|
439 | 453 | if (!result && type == 'EQ') {
|
440 |
| - assertion.push('Expected: ' + expected + ', Actual: ' + details.actual); |
| 454 | + message.push('Expected: ' + expected + ', Actual: ' + details.actual); |
441 | 455 | }
|
442 |
| - QUnit.config.testStats.assertions.push(assertion.join(' | ')); |
| 456 | + QUnit.config.extrasData.logs.push(message.join(' | ')); |
443 | 457 | });
|
444 | 458 |
|
445 | 459 | /**
|
|
469 | 483 | * @param {Object} details An object with properties `failed`, `name`, `passed`, and `total`.
|
470 | 484 | */
|
471 | 485 | QUnit.testDone(function(details) {
|
472 |
| - var assertions = QUnit.config.testStats.assertions, |
| 486 | + var logs = QUnit.config.extrasData.logs, |
473 | 487 | testName = details.name;
|
474 | 488 |
|
475 | 489 | if (details.failed > 0) {
|
|
480 | 494 | console.log(moduleName);
|
481 | 495 | console.log(hr);
|
482 | 496 | }
|
483 |
| - console.log(' FAIL - '+ testName); |
484 |
| - assertions.forEach(function(value) { |
485 |
| - console.log(' ' + value); |
486 |
| - }); |
| 497 | + var index = -1, |
| 498 | + length = logs.length; |
| 499 | + |
| 500 | + console.log(' FAIL - ' + testName); |
| 501 | + while(++index < length) { |
| 502 | + console.log(' ' + logs[index]); |
| 503 | + } |
487 | 504 | }
|
488 |
| - assertions.length = 0; |
| 505 | + logs.length = 0; |
489 | 506 | });
|
490 | 507 |
|
491 | 508 | /**
|
|
562 | 579 | /*--------------------------------------------------------------------------*/
|
563 | 580 |
|
564 | 581 | // expose QUnit extras
|
565 |
| - if (freeExports && !freeExports.nodeType) { |
| 582 | + if (freeExports) { |
566 | 583 | freeExports.runInContext = runInContext;
|
567 | 584 | } else {
|
568 | 585 | runInContext(root);
|
569 | 586 | }
|
570 |
| -}(this)); |
| 587 | +}.call(this)); |
0 commit comments