Skip to content

Commit 7a22ba0

Browse files
committed
Fix test fails in older Safari cause by qunit-extras.
1 parent bedeba4 commit 7a22ba0

File tree

1 file changed

+46
-29
lines changed

1 file changed

+46
-29
lines changed

vendor/qunit-extras/qunit-extras.js

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
* Based on a gist by Jörn Zaefferer <https://gist.github.com/722381>
55
* Available under MIT license <http://mths.be/mit>
66
*/
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 = '----------------------------------------';
914

1015
/** Native method shortcut */
1116
var unshift = Array.prototype.unshift;
@@ -27,15 +32,21 @@
2732
'&#39;': "'"
2833
};
2934

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;
3243

3344
/** Detect free variable `exports` */
34-
var freeExports = typeof exports == 'object' && exports;
45+
var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
3546

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)) {
3950
root = freeGlobal;
4051
}
4152

@@ -155,7 +166,7 @@
155166
* @param {number} delay The number of milliseconds to delay the `fn` call.
156167
* @param [arg1, arg2, ...] Arguments to invoke `fn` with.
157168
* @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.
159170
*/
160171
function schedule(fn, delay, args, repeated) {
161172
// Rhino 1.7RC4 will error assigning `task` below
@@ -204,7 +215,7 @@
204215
* @param {Function|string} fn The function to call or string to evaluate.
205216
* @param {number} delay The number of milliseconds to delay each `fn` call.
206217
* @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.
208219
*/
209220
function setInterval(fn, delay) {
210221
return schedule(fn, delay, slice.call(arguments, 2), true);
@@ -217,7 +228,7 @@
217228
* @param {Function|string} fn The function to call or string to evaluate.
218229
* @param {number} delay The number of milliseconds to delay the `fn` call.
219230
* @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.
221232
*/
222233
function setTimeout(fn, delay) {
223234
return schedule(fn, delay, slice.call(arguments, 2));
@@ -282,20 +293,20 @@
282293
QUnit.config.excused = {};
283294

284295
/**
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.
286297
*
287298
* @memberOf QUnit.config
288299
* @type Object
289300
*/
290-
QUnit.config.testStats = {
301+
QUnit.config.extrasData = {
291302

292303
/**
293-
* An array of test summaries.
304+
* An array of assertion logs.
294305
*
295-
* @memberOf QUnit.config.testStats
306+
* @memberOf QUnit.config.extrasData
296307
* @type Array
297308
*/
298-
'assertions': []
309+
'logs': []
299310
};
300311

301312
/**
@@ -317,14 +328,17 @@
317328
test.retries = 0;
318329
test.finish = function() {
319330
var asserts = this.assertions,
331+
config = QUnit.config,
320332
index = -1,
321333
length = asserts.length,
322-
queue = QUnit.config.queue;
334+
logs = config.extrasData.logs,
335+
queue = config.queue;
323336

324337
while (++index < length) {
325338
var assert = asserts[index];
326-
if (!assert.result && this.retries < QUnit.config.asyncRetries) {
339+
if (!assert.result && this.retries < config.asyncRetries) {
327340
this.retries++;
341+
logs.length = Math.max(0, logs.length - asserts.length);
328342
asserts.length = 0;
329343

330344
var oldLength = queue.length;
@@ -430,16 +444,16 @@
430444
result = details.result,
431445
type = typeof expected != 'undefined' ? 'EQ' : 'OK';
432446

433-
var assertion = [
447+
var message = [
434448
result ? 'PASS' : 'FAIL',
435449
type,
436450
details.message || 'ok'
437451
];
438452

439453
if (!result && type == 'EQ') {
440-
assertion.push('Expected: ' + expected + ', Actual: ' + details.actual);
454+
message.push('Expected: ' + expected + ', Actual: ' + details.actual);
441455
}
442-
QUnit.config.testStats.assertions.push(assertion.join(' | '));
456+
QUnit.config.extrasData.logs.push(message.join(' | '));
443457
});
444458

445459
/**
@@ -469,7 +483,7 @@
469483
* @param {Object} details An object with properties `failed`, `name`, `passed`, and `total`.
470484
*/
471485
QUnit.testDone(function(details) {
472-
var assertions = QUnit.config.testStats.assertions,
486+
var logs = QUnit.config.extrasData.logs,
473487
testName = details.name;
474488

475489
if (details.failed > 0) {
@@ -480,12 +494,15 @@
480494
console.log(moduleName);
481495
console.log(hr);
482496
}
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+
}
487504
}
488-
assertions.length = 0;
505+
logs.length = 0;
489506
});
490507

491508
/**
@@ -562,9 +579,9 @@
562579
/*--------------------------------------------------------------------------*/
563580

564581
// expose QUnit extras
565-
if (freeExports && !freeExports.nodeType) {
582+
if (freeExports) {
566583
freeExports.runInContext = runInContext;
567584
} else {
568585
runInContext(root);
569586
}
570-
}(this));
587+
}.call(this));

0 commit comments

Comments
 (0)