Fix qunit-extras sauce reporter.

This commit is contained in:
John-David Dalton
2014-09-05 10:57:57 -07:00
parent 13022a6bb0
commit 6643252019

View File

@@ -399,29 +399,61 @@
*/ */
QUnit.config.extrasData = { QUnit.config.extrasData = {
'logs': [],
/** /**
* An array of details for each log entry. * The data object for the active test module.
* *
* @memberOf QUnit.config.extrasData * @memberOf QUnit.config.extrasData
* @type Array * @type Object
*/ */
'module': {} 'module': {},
/**
* The data object for Sauce Labs.
*
* @memberOf QUnit.config.extrasData
* @type Object
*/
'sauce': {
/**
* An array of failed test details.
*
* @memberOf QUnit.config.extrasData.sauce
* @type Array
*/
'tests': []
}
}; };
// add a callback to be triggered when all testing has completed /**
QUnit.done(function(details) { * Converts an object into a string representation.
// assign results to `global_test_results` for Sauce Labs *
details.tests = QUnit.config.extrasData.logs; * @memberOf QUnit
context.global_test_results = details; * @type Function
}); * @param {Object} object The object to stringify.
* @returns {string} The result string.
*/
QUnit.jsDump.parsers.object = (function() {
var func = QUnit.jsDump.parsers.object;
if (isSilent) {
return func;
}
return function(object) {
if (typeof object.rhinoException != 'object') {
return func(object);
}
return object.name +
' { message: "' + object.message +
'", fileName: "' + object.fileName +
'", lineNumber: ' + object.lineNumber + ' }';
};
}());
/*------------------------------------------------------------------------*/
// add a callback to be triggered after every assertion // add a callback to be triggered after every assertion
QUnit.log(function(details) { QUnit.log(function(details) {
var data = QUnit.config.extrasData; QUnit.config.extrasData.module.logs.push(details);
data.logs.push(details);
data.module.logs.push(details);
}); });
// add a callback to be triggered at the start of every test module // add a callback to be triggered at the start of every test module
@@ -455,13 +487,11 @@
while (++index < length) { while (++index < length) {
var assert = asserts[index]; var assert = asserts[index];
if (!assert.result && this.retries < config.asyncRetries) { if (!assert.result && this.retries < config.asyncRetries) {
if (!isSilent) { var oldLength = queue.length;
logs.length -= asserts.length; logs.length -= asserts.length;
}
this.retries++;
asserts.length = 0; asserts.length = 0;
var oldLength = queue.length; this.retries++;
this.queue(); this.queue();
unshift.apply(queue, queue.splice(oldLength, queue.length - oldLength)); unshift.apply(queue, queue.splice(oldLength, queue.length - oldLength));
@@ -534,54 +564,20 @@
}); });
}); });
// replace poisoned `raises` method // add a callback to be triggered after a test is completed
context.raises = QUnit.raises = QUnit['throws'] || QUnit.raises; QUnit.testDone(function(details) {
var config = QUnit.config,
data = config.extrasData,
failures = details.failed,
hidepassed = config.hidepassed,
module = data.module,
moduleLogs = module.logs,
sauceTests = data.sauce.tests;
/*------------------------------------------------------------------------*/ if (hidepassed && !failures) {
return;
// add logging extras }
if (!isSilent) { if (!isSilent) {
// add a callback to be triggered when all testing has completed
QUnit.done(function(details) {
var failures = details.failed,
statusColor = failures ? 'magenta' : 'green';
logInline();
console.log(hr);
console.log(color(statusColor, ' PASS: ' + details.passed + ' FAIL: ' + failures + ' TOTAL: ' + details.total));
console.log(color(statusColor, ' Finished in ' + details.runtime + ' milliseconds.'));
console.log(hr);
// exit out of Node.js or PhantomJS
try {
if (failures) {
process.exit(1);
} else {
process.exit(0);
}
} catch(e) {}
// exit out of Narwhal, Rhino, or RingoJS
try {
if (failures) {
java.lang.System.exit(1);
} else {
quit();
}
} catch(e) {}
});
// add a callback to be triggered after a test is completed
QUnit.testDone(function(details) {
var config = QUnit.config,
module = config.extrasData.module,
logs = module.logs,
failures = details.failed,
hidepassed = config.hidepassed;
if (hidepassed && !failures) {
return;
}
logInline(); logInline();
if (!module.printed) { if (!module.printed) {
module.printed = true; module.printed = true;
@@ -590,59 +586,80 @@
console.log(hr); console.log(hr);
} }
console.log(' ' + (failures ? color('red', 'FAIL') : color('green', 'PASS')) + ' - ' + details.name); console.log(' ' + (failures ? color('red', 'FAIL') : color('green', 'PASS')) + ' - ' + details.name);
}
if (!failures) {
return;
}
var index = -1,
length = moduleLogs.length;
if (!failures) { while(++index < length) {
return; var entry = moduleLogs[index];
if (hidepassed && entry.result) {
continue;
} }
var index = -1, var expected = entry.expected,
length = logs.length; result = entry.result,
type = typeof expected != 'undefined' ? 'EQ' : 'OK';
while(++index < length) { var message = [
var log = logs[index]; result ? color('green', 'PASS') : color('red', 'FAIL'),
if (hidepassed && log.result) { type,
continue; entry.message || 'ok'
} ];
var expected = log.expected,
result = log.result,
type = typeof expected != 'undefined' ? 'EQ' : 'OK';
var message = [ if (!result && type == 'EQ') {
result ? color('green', 'PASS') : color('red', 'FAIL'), message.push(color('magenta', 'Expected: ' + expected + ', Actual: ' + entry.actual));
type, }
log.message || 'ok' if (!isSilent) {
];
if (!result && type == 'EQ') {
message.push(color('magenta', 'Expected: ' + expected + ', Actual: ' + log.actual));
}
console.log(' ' + message.join(' | ')); console.log(' ' + message.join(' | '));
} }
}); if (!entry.result) {
sauceTests.push(entry);
}
}
});
/** // add a callback to be triggered when all testing has completed
* Converts an object into a string representation. QUnit.done(function(details) {
* var failures = details.failed,
* @memberOf QUnit statusColor = failures ? 'magenta' : 'green';
* @type Function
* @param {Object} object The object to stringify. if (!isSilent) {
* @returns {string} The result string. logInline();
*/ console.log(hr);
QUnit.jsDump.parsers.object = (function() { console.log(color(statusColor, ' PASS: ' + details.passed + ' FAIL: ' + failures + ' TOTAL: ' + details.total));
var func = QUnit.jsDump.parsers.object; console.log(color(statusColor, ' Finished in ' + details.runtime + ' milliseconds.'));
return function(object) { console.log(hr);
if (typeof object.rhinoException != 'object') { }
return func(object); // exit out of Node.js or PhantomJS
} try {
return object.name + if (failures) {
' { message: "' + object.message + process.exit(1);
'", fileName: "' + object.fileName + } else {
'", lineNumber: ' + object.lineNumber + ' }'; process.exit(0);
}; }
}()); } catch(e) {}
}
// exit out of Narwhal, Rhino, or RingoJS
try {
if (failures) {
java.lang.System.exit(1);
} else {
quit();
}
} catch(e) {}
// assign results to `global_test_results` for Sauce Labs
details.tests = QUnit.config.extrasData.sauce.tests;
context.global_test_results = details;
});
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
// replace poisoned `raises` method
context.raises = QUnit.raises = QUnit['throws'] || QUnit.raises;
// add CLI extras // add CLI extras
if (!document) { if (!document) {
// Timeout fallbacks based on the work of Andrea Giammarchi and Weston C. // Timeout fallbacks based on the work of Andrea Giammarchi and Weston C.