Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added warnings to xunit xml output

  • Loading branch information...
commit 2b819b07e767bbcffe05d51abf4e5d9e729cef00 1 parent 14a9a8b
@n1k0 authored
Showing with 64 additions and 20 deletions.
  1. +47 −19 modules/tester.js
  2. +17 −1 modules/xunit.js
View
66 modules/tester.js
@@ -161,6 +161,12 @@ var Tester = function Tester(casper, options) {
}
self.done();
});
+
+ this.casper.on('warn', function(warning) {
+ if (self.currentSuite) {
+ self.currentSuite.addWarning(warning);
+ }
+ });
};
// Tester class is an EventEmitter
@@ -857,16 +863,7 @@ Tester.prototype.done = function done(planned) {
*/
Tester.prototype.dubious = function dubious(planned, executed) {
"use strict";
- var message = f('%d tests planned, %d tests executed', planned, executed);
- this.currentSuite.addWarning({
- message: message,
- file: this.currentTestFile,
- values: {
- planned: planned,
- executed: executed
- }
- });
- this.casper.warn(message);
+ this.casper.warn(f('%d tests planned, %d tests executed', planned, executed));
};
/**
@@ -1025,7 +1022,6 @@ Tester.prototype.processAssertionResult = function processAssertionResult(result
style = 'RED_BAR';
status = this.options.failText;
}
- style = result.type === "dubious" ? "WARN_BAR" : style;
this.casper.echo([this.colorize(status, style), this.formatMessage(message)].join(' '));
this.emit(eventName, result);
if (this.options.failFast && !result.success) {
@@ -1040,10 +1036,10 @@ Tester.prototype.processAssertionResult = function processAssertionResult(result
*/
Tester.prototype.renderFailureDetails = function renderFailureDetails() {
"use strict";
- var failures = this.suiteResults.getAllFailures();
- if (failures.length === 0) {
+ if (!this.suiteResults.isFailed()) {
return;
}
+ var failures = this.suiteResults.getAllFailures();
this.casper.echo(f("\nDetails for the %d failed test%s:\n",
failures.length, failures.length > 1 ? "s" : ""), "PARAMETER");
failures.forEach(function _forEach(failure) {
@@ -1113,11 +1109,9 @@ Tester.prototype.runSuites = function runSuites() {
this.loadIncludes.includes.forEach(function _forEachInclude(include) {
phantom.injectJs(include);
});
-
this.loadIncludes.pre.forEach(function _forEachPreTest(preTestFile) {
testFiles = testFiles.concat(preTestFile);
});
-
Array.prototype.forEach.call(arguments, function _forEachArgument(path) {
if (!fs.exists(path)) {
self.bar(f("Path %s doesn't exist", path), "RED_BAR");
@@ -1128,21 +1122,17 @@ Tester.prototype.runSuites = function runSuites() {
testFiles.push(path);
}
});
-
this.loadIncludes.post.forEach(function _forEachPostTest(postTestFile) {
testFiles = testFiles.concat(postTestFile);
});
-
if (testFiles.length === 0) {
this.bar(f("No test file found in %s, aborting.",
Array.prototype.slice.call(arguments)), "RED_BAR");
this.casper.exit(1);
}
-
self.currentSuiteNum = 0;
self.currentTestStartTime = new Date();
self.lastAssertTime = 0;
-
var interval = setInterval(function _check(self) {
if (self.running) {
return;
@@ -1243,6 +1233,20 @@ TestSuiteResult.prototype.countTotal = function countTotal() {
};
/**
+ * Returns the number of errors.
+ *
+ * @return Number
+ */
+TestSuiteResult.prototype.countErrors = function countErrors() {
+ "use strict";
+ return this.map(function(result) {
+ return result.crashed;
+ }).reduce(function(a, b) {
+ return a + b;
+ }, 0);
+};
+
+/**
* Returns the number of failed tests.
*
* @return Number
@@ -1271,6 +1275,30 @@ TestSuiteResult.prototype.countPassed = function countPassed() {
};
/**
+ * Returns the number of warnings.
+ *
+ * @return Number
+ */
+TestSuiteResult.prototype.countWarnings = function countWarnings() {
+ "use strict";
+ return this.map(function(result) {
+ return result.warned;
+ }).reduce(function(a, b) {
+ return a + b;
+ }, 0);
+};
+
+/**
+ * Checks if the suite has failed.
+ *
+ * @return Number
+ */
+TestSuiteResult.prototype.isFailed = function isFailed() {
+ "use strict";
+ return this.countErrors() + this.countFailed() > 0;
+};
+
+/**
* Returns all failures from this suite.
*
* @return Array
View
18 modules/xunit.js
@@ -100,10 +100,13 @@ XUnitExporter.prototype.getXML = function getXML() {
var suiteNode = utils.node('testsuite', {
name: result.name,
tests: result.assertions,
- failures: result.failures.length,
+ failures: result.failed,
+ errors: result.crashed,
time: utils.ms2seconds(result.calculateDuration()),
+ timestamp: (new Date()).toISOString(),
'package': generateClassName(result.file)
});
+ // succesful test cases
result.passes.forEach(function(success) {
var testCase = utils.node('testcase', {
name: success.message || success.standard,
@@ -112,6 +115,7 @@ XUnitExporter.prototype.getXML = function getXML() {
});
suiteNode.appendChild(testCase);
});
+ // failed test cases
result.failures.forEach(function(failure) {
var testCase = utils.node('testcase', {
name: failure.message || failure.standard,
@@ -132,6 +136,18 @@ XUnitExporter.prototype.getXML = function getXML() {
testCase.appendChild(failureNode);
suiteNode.appendChild(testCase);
});
+ // errors
+ result.errors.forEach(function(error) {
+ var errorNode = utils.node('error', {
+ type: error.name
+ });
+ errorNode.appendChild(document.createTextNode(error.stack ? error.stack : error.message));
+ suiteNode.appendChild(errorNode);
+ });
+ // warnings
+ var warningNode = utils.node('system-out');
+ warningNode.appendChild(document.createTextNode(result.warnings.join('\n')));
+ suiteNode.appendChild(warningNode);
this._xml.appendChild(suiteNode);
}.bind(this));
this._xml.setAttribute('duration', utils.ms2seconds(this.results.calculateDuration()));
Please sign in to comment.
Something went wrong with that request. Please try again.