Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Update vendor/qunit-extras and simplify its load/install.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Jan 25, 2014
1 parent 1987996 commit eef4572
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 26 deletions.
36 changes: 27 additions & 9 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
;(function(root, undefined) {
'use strict';
;(function() {

/** Used as a safe reference for `undefined` in pre ES5 environments */
var undefined;

/** Used as a reference to the global object */
var root = typeof global == 'object' && global || this;

/** Method and object shortcuts */
var phantom = root.phantom,
amd = root.define && define.amd,
document = !phantom && root.document,
noop = function() {},
slice = Array.prototype.slice;

/** Detect if running in Java */
var isJava = !document && !!root.java;

/** Use a single "load" function */
var load = typeof require == 'function' ? require : root.load;
var load = (typeof require == 'function' && !amd)
? require
: (isJava && root.load) || noop;

/** The unit testing framework */
var QUnit = (function() {
var noop = Function.prototype;
return root.QUnit || (
root.addEventListener || (root.addEventListener = noop),
root.setTimeout || (root.setTimeout = noop),
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,
root.QUnit
);
Expand Down Expand Up @@ -47,8 +62,11 @@
}
};

/** Shortcut used to convert array-like objects to arrays */
var slice = Array.prototype.slice;
/** Load and install QUnit Extras */
var qa = load('../vendor/qunit-extras/qunit-extras.js');
if (qa) {
qa.runInContext(root);
}

/*--------------------------------------------------------------------------*/

Expand Down Expand Up @@ -1274,8 +1292,8 @@

QUnit.config.asyncRetries = 10;

if (!root.document || root.phantom) {
if (!document) {
QUnit.config.noglobals = true;
QUnit.start();
}
}(typeof global == 'object' && global || this));
}.call(this));
39 changes: 22 additions & 17 deletions vendor/qunit-extras/qunit-extras.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* Available under MIT license <http:https://mths.be/mit>
*/
;(function() {
'use strict';

/** Used as a safe reference for `undefined` in pre ES5 environments */
var undefined;
Expand Down Expand Up @@ -294,20 +293,20 @@
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
* @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
*/
'assertions': []
'logs': []
};

/**
Expand All @@ -329,14 +328,17 @@
test.retries = 0;
test.finish = function() {
var asserts = this.assertions,
config = QUnit.config,
index = -1,
length = asserts.length,
queue = QUnit.config.queue;
logs = config.extrasData.logs,
queue = config.queue;

while (++index < length) {
var assert = asserts[index];
if (!assert.result && this.retries < QUnit.config.asyncRetries) {
if (!assert.result && this.retries < config.asyncRetries) {
this.retries++;
logs.length = Math.max(0, logs.length - asserts.length);
asserts.length = 0;

var oldLength = queue.length;
Expand Down Expand Up @@ -442,16 +444,16 @@
result = details.result,
type = typeof expected != 'undefined' ? 'EQ' : 'OK';

var assertion = [
var message = [
result ? 'PASS' : 'FAIL',
type,
details.message || 'ok'
];

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(' | '));
});

/**
Expand Down Expand Up @@ -481,7 +483,7 @@
* @param {Object} details An object with properties `failed`, `name`, `passed`, and `total`.
*/
QUnit.testDone(function(details) {
var assertions = QUnit.config.testStats.assertions,
var logs = QUnit.config.extrasData.logs,
testName = details.name;

if (details.failed > 0) {
Expand All @@ -492,12 +494,15 @@
console.log(moduleName);
console.log(hr);
}
console.log(' FAIL - '+ testName);
assertions.forEach(function(value) {
console.log(' ' + value);
});
var index = -1,
length = logs.length;

console.log(' FAIL - ' + testName);
while(++index < length) {
console.log(' ' + logs[index]);
}
}
assertions.length = 0;
logs.length = 0;
});

/**
Expand Down

0 comments on commit eef4572

Please sign in to comment.