Commit 2b819b07 2b819b07e767bbcffe05d51abf4e5d9e729cef00 by Nicolas Perriault

added warnings to xunit xml output

1 parent 14a9a8bd
...@@ -161,6 +161,12 @@ var Tester = function Tester(casper, options) { ...@@ -161,6 +161,12 @@ var Tester = function Tester(casper, options) {
161 } 161 }
162 self.done(); 162 self.done();
163 }); 163 });
164
165 this.casper.on('warn', function(warning) {
166 if (self.currentSuite) {
167 self.currentSuite.addWarning(warning);
168 }
169 });
164 }; 170 };
165 171
166 // Tester class is an EventEmitter 172 // Tester class is an EventEmitter
...@@ -857,16 +863,7 @@ Tester.prototype.done = function done(planned) { ...@@ -857,16 +863,7 @@ Tester.prototype.done = function done(planned) {
857 */ 863 */
858 Tester.prototype.dubious = function dubious(planned, executed) { 864 Tester.prototype.dubious = function dubious(planned, executed) {
859 "use strict"; 865 "use strict";
860 var message = f('%d tests planned, %d tests executed', planned, executed); 866 this.casper.warn(f('%d tests planned, %d tests executed', planned, executed));
861 this.currentSuite.addWarning({
862 message: message,
863 file: this.currentTestFile,
864 values: {
865 planned: planned,
866 executed: executed
867 }
868 });
869 this.casper.warn(message);
870 }; 867 };
871 868
872 /** 869 /**
...@@ -1025,7 +1022,6 @@ Tester.prototype.processAssertionResult = function processAssertionResult(result ...@@ -1025,7 +1022,6 @@ Tester.prototype.processAssertionResult = function processAssertionResult(result
1025 style = 'RED_BAR'; 1022 style = 'RED_BAR';
1026 status = this.options.failText; 1023 status = this.options.failText;
1027 } 1024 }
1028 style = result.type === "dubious" ? "WARN_BAR" : style;
1029 this.casper.echo([this.colorize(status, style), this.formatMessage(message)].join(' ')); 1025 this.casper.echo([this.colorize(status, style), this.formatMessage(message)].join(' '));
1030 this.emit(eventName, result); 1026 this.emit(eventName, result);
1031 if (this.options.failFast && !result.success) { 1027 if (this.options.failFast && !result.success) {
...@@ -1040,10 +1036,10 @@ Tester.prototype.processAssertionResult = function processAssertionResult(result ...@@ -1040,10 +1036,10 @@ Tester.prototype.processAssertionResult = function processAssertionResult(result
1040 */ 1036 */
1041 Tester.prototype.renderFailureDetails = function renderFailureDetails() { 1037 Tester.prototype.renderFailureDetails = function renderFailureDetails() {
1042 "use strict"; 1038 "use strict";
1043 var failures = this.suiteResults.getAllFailures(); 1039 if (!this.suiteResults.isFailed()) {
1044 if (failures.length === 0) {
1045 return; 1040 return;
1046 } 1041 }
1042 var failures = this.suiteResults.getAllFailures();
1047 this.casper.echo(f("\nDetails for the %d failed test%s:\n", 1043 this.casper.echo(f("\nDetails for the %d failed test%s:\n",
1048 failures.length, failures.length > 1 ? "s" : ""), "PARAMETER"); 1044 failures.length, failures.length > 1 ? "s" : ""), "PARAMETER");
1049 failures.forEach(function _forEach(failure) { 1045 failures.forEach(function _forEach(failure) {
...@@ -1113,11 +1109,9 @@ Tester.prototype.runSuites = function runSuites() { ...@@ -1113,11 +1109,9 @@ Tester.prototype.runSuites = function runSuites() {
1113 this.loadIncludes.includes.forEach(function _forEachInclude(include) { 1109 this.loadIncludes.includes.forEach(function _forEachInclude(include) {
1114 phantom.injectJs(include); 1110 phantom.injectJs(include);
1115 }); 1111 });
1116
1117 this.loadIncludes.pre.forEach(function _forEachPreTest(preTestFile) { 1112 this.loadIncludes.pre.forEach(function _forEachPreTest(preTestFile) {
1118 testFiles = testFiles.concat(preTestFile); 1113 testFiles = testFiles.concat(preTestFile);
1119 }); 1114 });
1120
1121 Array.prototype.forEach.call(arguments, function _forEachArgument(path) { 1115 Array.prototype.forEach.call(arguments, function _forEachArgument(path) {
1122 if (!fs.exists(path)) { 1116 if (!fs.exists(path)) {
1123 self.bar(f("Path %s doesn't exist", path), "RED_BAR"); 1117 self.bar(f("Path %s doesn't exist", path), "RED_BAR");
...@@ -1128,21 +1122,17 @@ Tester.prototype.runSuites = function runSuites() { ...@@ -1128,21 +1122,17 @@ Tester.prototype.runSuites = function runSuites() {
1128 testFiles.push(path); 1122 testFiles.push(path);
1129 } 1123 }
1130 }); 1124 });
1131
1132 this.loadIncludes.post.forEach(function _forEachPostTest(postTestFile) { 1125 this.loadIncludes.post.forEach(function _forEachPostTest(postTestFile) {
1133 testFiles = testFiles.concat(postTestFile); 1126 testFiles = testFiles.concat(postTestFile);
1134 }); 1127 });
1135
1136 if (testFiles.length === 0) { 1128 if (testFiles.length === 0) {
1137 this.bar(f("No test file found in %s, aborting.", 1129 this.bar(f("No test file found in %s, aborting.",
1138 Array.prototype.slice.call(arguments)), "RED_BAR"); 1130 Array.prototype.slice.call(arguments)), "RED_BAR");
1139 this.casper.exit(1); 1131 this.casper.exit(1);
1140 } 1132 }
1141
1142 self.currentSuiteNum = 0; 1133 self.currentSuiteNum = 0;
1143 self.currentTestStartTime = new Date(); 1134 self.currentTestStartTime = new Date();
1144 self.lastAssertTime = 0; 1135 self.lastAssertTime = 0;
1145
1146 var interval = setInterval(function _check(self) { 1136 var interval = setInterval(function _check(self) {
1147 if (self.running) { 1137 if (self.running) {
1148 return; 1138 return;
...@@ -1243,6 +1233,20 @@ TestSuiteResult.prototype.countTotal = function countTotal() { ...@@ -1243,6 +1233,20 @@ TestSuiteResult.prototype.countTotal = function countTotal() {
1243 }; 1233 };
1244 1234
1245 /** 1235 /**
1236 * Returns the number of errors.
1237 *
1238 * @return Number
1239 */
1240 TestSuiteResult.prototype.countErrors = function countErrors() {
1241 "use strict";
1242 return this.map(function(result) {
1243 return result.crashed;
1244 }).reduce(function(a, b) {
1245 return a + b;
1246 }, 0);
1247 };
1248
1249 /**
1246 * Returns the number of failed tests. 1250 * Returns the number of failed tests.
1247 * 1251 *
1248 * @return Number 1252 * @return Number
...@@ -1271,6 +1275,30 @@ TestSuiteResult.prototype.countPassed = function countPassed() { ...@@ -1271,6 +1275,30 @@ TestSuiteResult.prototype.countPassed = function countPassed() {
1271 }; 1275 };
1272 1276
1273 /** 1277 /**
1278 * Returns the number of warnings.
1279 *
1280 * @return Number
1281 */
1282 TestSuiteResult.prototype.countWarnings = function countWarnings() {
1283 "use strict";
1284 return this.map(function(result) {
1285 return result.warned;
1286 }).reduce(function(a, b) {
1287 return a + b;
1288 }, 0);
1289 };
1290
1291 /**
1292 * Checks if the suite has failed.
1293 *
1294 * @return Number
1295 */
1296 TestSuiteResult.prototype.isFailed = function isFailed() {
1297 "use strict";
1298 return this.countErrors() + this.countFailed() > 0;
1299 };
1300
1301 /**
1274 * Returns all failures from this suite. 1302 * Returns all failures from this suite.
1275 * 1303 *
1276 * @return Array 1304 * @return Array
......
...@@ -100,10 +100,13 @@ XUnitExporter.prototype.getXML = function getXML() { ...@@ -100,10 +100,13 @@ XUnitExporter.prototype.getXML = function getXML() {
100 var suiteNode = utils.node('testsuite', { 100 var suiteNode = utils.node('testsuite', {
101 name: result.name, 101 name: result.name,
102 tests: result.assertions, 102 tests: result.assertions,
103 failures: result.failures.length, 103 failures: result.failed,
104 errors: result.crashed,
104 time: utils.ms2seconds(result.calculateDuration()), 105 time: utils.ms2seconds(result.calculateDuration()),
106 timestamp: (new Date()).toISOString(),
105 'package': generateClassName(result.file) 107 'package': generateClassName(result.file)
106 }); 108 });
109 // succesful test cases
107 result.passes.forEach(function(success) { 110 result.passes.forEach(function(success) {
108 var testCase = utils.node('testcase', { 111 var testCase = utils.node('testcase', {
109 name: success.message || success.standard, 112 name: success.message || success.standard,
...@@ -112,6 +115,7 @@ XUnitExporter.prototype.getXML = function getXML() { ...@@ -112,6 +115,7 @@ XUnitExporter.prototype.getXML = function getXML() {
112 }); 115 });
113 suiteNode.appendChild(testCase); 116 suiteNode.appendChild(testCase);
114 }); 117 });
118 // failed test cases
115 result.failures.forEach(function(failure) { 119 result.failures.forEach(function(failure) {
116 var testCase = utils.node('testcase', { 120 var testCase = utils.node('testcase', {
117 name: failure.message || failure.standard, 121 name: failure.message || failure.standard,
...@@ -132,6 +136,18 @@ XUnitExporter.prototype.getXML = function getXML() { ...@@ -132,6 +136,18 @@ XUnitExporter.prototype.getXML = function getXML() {
132 testCase.appendChild(failureNode); 136 testCase.appendChild(failureNode);
133 suiteNode.appendChild(testCase); 137 suiteNode.appendChild(testCase);
134 }); 138 });
139 // errors
140 result.errors.forEach(function(error) {
141 var errorNode = utils.node('error', {
142 type: error.name
143 });
144 errorNode.appendChild(document.createTextNode(error.stack ? error.stack : error.message));
145 suiteNode.appendChild(errorNode);
146 });
147 // warnings
148 var warningNode = utils.node('system-out');
149 warningNode.appendChild(document.createTextNode(result.warnings.join('\n')));
150 suiteNode.appendChild(warningNode);
135 this._xml.appendChild(suiteNode); 151 this._xml.appendChild(suiteNode);
136 }.bind(this)); 152 }.bind(this));
137 this._xml.setAttribute('duration', utils.ms2seconds(this.results.calculateDuration())); 153 this._xml.setAttribute('duration', utils.ms2seconds(this.results.calculateDuration()));
......