Update vendor/qunit-extras and simplify its load/install.

This commit is contained in:
John-David Dalton
2014-01-24 09:23:26 -08:00
parent 44fa3d2d07
commit 087ed0aa6a
2 changed files with 28 additions and 19 deletions

View File

@@ -83,7 +83,7 @@
/** Use a single "load" function */ /** Use a single "load" function */
var load = (typeof require == 'function' && !amd) var load = (typeof require == 'function' && !amd)
? require ? require
: (isJava && root.load); : (isJava && root.load) || noop;
/** The unit testing framework */ /** The unit testing framework */
var QUnit = (function() { var QUnit = (function() {
@@ -91,12 +91,17 @@
root.addEventListener || (root.addEventListener = noop), root.addEventListener || (root.addEventListener = noop),
root.setTimeout || (root.setTimeout = noop), root.setTimeout || (root.setTimeout = noop),
root.QUnit = load('../vendor/qunit/qunit/qunit.js') || root.QUnit, root.QUnit = load('../vendor/qunit/qunit/qunit.js') || root.QUnit,
(load('../vendor/qunit-extras/qunit-extras.js') || { 'runInContext': noop }).runInContext(root),
addEventListener === noop && delete root.addEventListener, addEventListener === noop && delete root.addEventListener,
root.QUnit root.QUnit
); );
}()); }());
/** Load and install QUnit Extras */
var qa = load('../vendor/qunit-extras/qunit-extras.js');
if (qa) {
qa.runInContext(root);
}
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
// log params provided to `test.js` // log params provided to `test.js`

View File

@@ -5,7 +5,6 @@
* Available under MIT license <http://mths.be/mit> * Available under MIT license <http://mths.be/mit>
*/ */
;(function() { ;(function() {
'use strict';
/** Used as a safe reference for `undefined` in pre ES5 environments */ /** Used as a safe reference for `undefined` in pre ES5 environments */
var undefined; var undefined;
@@ -294,20 +293,20 @@
QUnit.config.excused = {}; QUnit.config.excused = {};
/** /**
* An object used to hold information about the current running test. * An object used to hold "extras" information about the current running test.
* *
* @memberOf QUnit.config * @memberOf QUnit.config
* @type Object * @type Object
*/ */
QUnit.config.testStats = { QUnit.config.extrasData = {
/** /**
* An array of test summaries. * An array of assertion logs.
* *
* @memberOf QUnit.config.testStats * @memberOf QUnit.config.extrasData
* @type Array * @type Array
*/ */
'assertions': [] 'logs': []
}; };
/** /**
@@ -329,14 +328,16 @@
test.retries = 0; test.retries = 0;
test.finish = function() { test.finish = function() {
var asserts = this.assertions, var asserts = this.assertions,
config = QUnit.config,
index = -1, index = -1,
length = asserts.length, length = asserts.length,
queue = QUnit.config.queue; queue = config.queue;
while (++index < length) { while (++index < length) {
var assert = asserts[index]; var assert = asserts[index];
if (!assert.result && this.retries < QUnit.config.asyncRetries) { if (!assert.result && this.retries < config.asyncRetries) {
this.retries++; this.retries++;
config.extrasData.logs.length -= asserts.length;
asserts.length = 0; asserts.length = 0;
var oldLength = queue.length; var oldLength = queue.length;
@@ -442,16 +443,16 @@
result = details.result, result = details.result,
type = typeof expected != 'undefined' ? 'EQ' : 'OK'; type = typeof expected != 'undefined' ? 'EQ' : 'OK';
var assertion = [ var message = [
result ? 'PASS' : 'FAIL', result ? 'PASS' : 'FAIL',
type, type,
details.message || 'ok' details.message || 'ok'
]; ];
if (!result && type == 'EQ') { if (!result && type == 'EQ') {
assertion.push('Expected: ' + expected + ', Actual: ' + details.actual); message.push('Expected: ' + expected + ', Actual: ' + details.actual);
} }
QUnit.config.testStats.assertions.push(assertion.join(' | ')); QUnit.config.extrasData.logs.push(message.join(' | '));
}); });
/** /**
@@ -481,7 +482,7 @@
* @param {Object} details An object with properties `failed`, `name`, `passed`, and `total`. * @param {Object} details An object with properties `failed`, `name`, `passed`, and `total`.
*/ */
QUnit.testDone(function(details) { QUnit.testDone(function(details) {
var assertions = QUnit.config.testStats.assertions, var logs = QUnit.config.extrasData.logs,
testName = details.name; testName = details.name;
if (details.failed > 0) { if (details.failed > 0) {
@@ -492,12 +493,15 @@
console.log(moduleName); console.log(moduleName);
console.log(hr); console.log(hr);
} }
console.log(' FAIL - '+ testName); var index = -1,
assertions.forEach(function(value) { length = logs.length;
console.log(' ' + value);
}); console.log(' FAIL - ' + testName);
while(++index < length) {
console.log(' ' + logs[index]);
}
} }
assertions.length = 0; logs.length = 0;
}); });
/** /**