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 = {
'logs': [],
/**
* An array of details for each log entry.
* The data object for the active test module.
*
* @memberOf QUnit.config.extrasData
* @type Object
*/
'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
*/
'module': {}
'tests': []
}
};
// add a callback to be triggered when all testing has completed
QUnit.done(function(details) {
// assign results to `global_test_results` for Sauce Labs
details.tests = QUnit.config.extrasData.logs;
context.global_test_results = details;
});
/**
* Converts an object into a string representation.
*
* @memberOf QUnit
* @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
QUnit.log(function(details) {
var data = QUnit.config.extrasData;
data.logs.push(details);
data.module.logs.push(details);
QUnit.config.extrasData.module.logs.push(details);
});
// add a callback to be triggered at the start of every test module
@@ -455,13 +487,11 @@
while (++index < length) {
var assert = asserts[index];
if (!assert.result && this.retries < config.asyncRetries) {
if (!isSilent) {
var oldLength = queue.length;
logs.length -= asserts.length;
}
this.retries++;
asserts.length = 0;
var oldLength = queue.length;
this.retries++;
this.queue();
unshift.apply(queue, queue.splice(oldLength, queue.length - oldLength));
@@ -534,24 +564,74 @@
});
});
// replace poisoned `raises` method
context.raises = QUnit.raises = QUnit['throws'] || QUnit.raises;
// add a callback to be triggered after a test is completed
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;
/*------------------------------------------------------------------------*/
// add logging extras
if (hidepassed && !failures) {
return;
}
if (!isSilent) {
logInline();
if (!module.printed) {
module.printed = true;
console.log(hr);
console.log(color('bold', module.name));
console.log(hr);
}
console.log(' ' + (failures ? color('red', 'FAIL') : color('green', 'PASS')) + ' - ' + details.name);
}
if (!failures) {
return;
}
var index = -1,
length = moduleLogs.length;
while(++index < length) {
var entry = moduleLogs[index];
if (hidepassed && entry.result) {
continue;
}
var expected = entry.expected,
result = entry.result,
type = typeof expected != 'undefined' ? 'EQ' : 'OK';
var message = [
result ? color('green', 'PASS') : color('red', 'FAIL'),
type,
entry.message || 'ok'
];
if (!result && type == 'EQ') {
message.push(color('magenta', 'Expected: ' + expected + ', Actual: ' + entry.actual));
}
if (!isSilent) {
console.log(' ' + message.join(' | '));
}
if (!entry.result) {
sauceTests.push(entry);
}
}
});
// add a callback to be triggered when all testing has completed
QUnit.done(function(details) {
var failures = details.failed,
statusColor = failures ? 'magenta' : 'green';
if (!isSilent) {
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) {
@@ -569,80 +649,17 @@
quit();
}
} catch(e) {}
// assign results to `global_test_results` for Sauce Labs
details.tests = QUnit.config.extrasData.sauce.tests;
context.global_test_results = details;
});
// 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();
if (!module.printed) {
module.printed = true;
console.log(hr);
console.log(color('bold', module.name));
console.log(hr);
}
console.log(' ' + (failures ? color('red', 'FAIL') : color('green', 'PASS')) + ' - ' + details.name);
if (!failures) {
return;
}
var index = -1,
length = logs.length;
while(++index < length) {
var log = logs[index];
if (hidepassed && log.result) {
continue;
}
var expected = log.expected,
result = log.result,
type = typeof expected != 'undefined' ? 'EQ' : 'OK';
var message = [
result ? color('green', 'PASS') : color('red', 'FAIL'),
type,
log.message || 'ok'
];
if (!result && type == 'EQ') {
message.push(color('magenta', 'Expected: ' + expected + ', Actual: ' + log.actual));
}
console.log(' ' + message.join(' | '));
}
});
/**
* Converts an object into a string representation.
*
* @memberOf QUnit
* @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;
return function(object) {
if (typeof object.rhinoException != 'object') {
return func(object);
}
return object.name +
' { message: "' + object.message +
'", fileName: "' + object.fileName +
'", lineNumber: ' + object.lineNumber + ' }';
};
}());
}
/*------------------------------------------------------------------------*/
// replace poisoned `raises` method
context.raises = QUnit.raises = QUnit['throws'] || QUnit.raises;
// add CLI extras
if (!document) {
// Timeout fallbacks based on the work of Andrea Giammarchi and Weston C.