terminate() actually terminates a suite
Showing
1 changed file
with
32 additions
and
9 deletions
... | @@ -123,6 +123,10 @@ var Tester = function Tester(casper, options) { | ... | @@ -123,6 +123,10 @@ var Tester = function Tester(casper, options) { |
123 | var valueKeys = Object.keys(failure.values), | 123 | var valueKeys = Object.keys(failure.values), |
124 | timeElapsed = new Date() - this.currentTestStartTime; | 124 | timeElapsed = new Date() - this.currentTestStartTime; |
125 | this.currentSuite.addFailure(failure, timeElapsed - this.lastAssertTime); | 125 | this.currentSuite.addFailure(failure, timeElapsed - this.lastAssertTime); |
126 | // check for fast failing | ||
127 | if (this.options.failFast) { | ||
128 | return this.terminate('--fail-fast: aborted all remaining tests'); | ||
129 | } | ||
126 | this.lastAssertTime = timeElapsed; | 130 | this.lastAssertTime = timeElapsed; |
127 | // special printing | 131 | // special printing |
128 | if (failure.type) { | 132 | if (failure.type) { |
... | @@ -160,7 +164,7 @@ var Tester = function Tester(casper, options) { | ... | @@ -160,7 +164,7 @@ var Tester = function Tester(casper, options) { |
160 | return; | 164 | return; |
161 | } | 165 | } |
162 | if (error === self.SKIP_MESSAGE) { | 166 | if (error === self.SKIP_MESSAGE) { |
163 | return self.abort('--fail-fast: aborted all remaining tests'); | 167 | return self.terminate('--fail-fast: aborted all remaining tests'); |
164 | } | 168 | } |
165 | var line = 0; | 169 | var line = 0; |
166 | try { | 170 | try { |
... | @@ -211,9 +215,10 @@ exports.Tester = Tester; | ... | @@ -211,9 +215,10 @@ exports.Tester = Tester; |
211 | */ | 215 | */ |
212 | Tester.prototype.abort = function abort(message) { | 216 | Tester.prototype.abort = function abort(message) { |
213 | "use strict"; | 217 | "use strict"; |
214 | this.aborted = true; | 218 | if (message) { |
215 | this.casper.warn(message || 'test suite aborted'); | 219 | this.casper.warn('test suite aborted: ' + message); |
216 | this.done(); | 220 | } |
221 | throw this.SKIP_MESSAGE; | ||
217 | }; | 222 | }; |
218 | 223 | ||
219 | /** | 224 | /** |
... | @@ -1146,9 +1151,6 @@ Tester.prototype.processAssertionResult = function processAssertionResult(result | ... | @@ -1146,9 +1151,6 @@ Tester.prototype.processAssertionResult = function processAssertionResult(result |
1146 | this.casper.echo([this.colorize(status, style), this.formatMessage(message)].join(' ')); | 1151 | this.casper.echo([this.colorize(status, style), this.formatMessage(message)].join(' ')); |
1147 | } | 1152 | } |
1148 | this.emit(eventName, result); | 1153 | this.emit(eventName, result); |
1149 | if (this.options.failFast && !result.success) { | ||
1150 | throw this.SKIP_MESSAGE; | ||
1151 | } | ||
1152 | return result; | 1154 | return result; |
1153 | }; | 1155 | }; |
1154 | 1156 | ||
... | @@ -1162,6 +1164,9 @@ Tester.prototype.processError = function processError(error) { | ... | @@ -1162,6 +1164,9 @@ Tester.prototype.processError = function processError(error) { |
1162 | if (error instanceof AssertionError) { | 1164 | if (error instanceof AssertionError) { |
1163 | return this.processAssertionError(error); | 1165 | return this.processAssertionError(error); |
1164 | } | 1166 | } |
1167 | if (error === this.SKIP_MESSAGE) { | ||
1168 | return this.terminate(); | ||
1169 | } | ||
1165 | return this.uncaughtError(error, this.currentTestFile, error.line); | 1170 | return this.uncaughtError(error, this.currentTestFile, error.line); |
1166 | }; | 1171 | }; |
1167 | 1172 | ||
... | @@ -1177,7 +1182,11 @@ Tester.prototype.processPhantomError = function processPhantomError(msg, backtra | ... | @@ -1177,7 +1182,11 @@ Tester.prototype.processPhantomError = function processPhantomError(msg, backtra |
1177 | this.casper.warn('looks you did not use begin() which is mandatory since 1.1'); | 1182 | this.casper.warn('looks you did not use begin() which is mandatory since 1.1'); |
1178 | } | 1183 | } |
1179 | if (msg === this.SKIP_MESSAGE) { | 1184 | if (msg === this.SKIP_MESSAGE) { |
1180 | return this.abort('--fail-fast: aborted all remaining tests'); | 1185 | var message = 'test suite aborted'; |
1186 | if (backtrace && backtrace[0]) { | ||
1187 | message += ' at ' + backtrace[0].file + backtrace[0].line; | ||
1188 | } | ||
1189 | return this.terminate(message); | ||
1181 | } | 1190 | } |
1182 | this.fail(msg, { | 1191 | this.fail(msg, { |
1183 | type: "error", | 1192 | type: "error", |
... | @@ -1289,7 +1298,7 @@ Tester.prototype.runSuites = function runSuites() { | ... | @@ -1289,7 +1298,7 @@ Tester.prototype.runSuites = function runSuites() { |
1289 | testFiles = testFiles.concat(postTestFile); | 1298 | testFiles = testFiles.concat(postTestFile); |
1290 | }); | 1299 | }); |
1291 | if (testFiles.length === 0) { | 1300 | if (testFiles.length === 0) { |
1292 | this.bar(f("No test file found in %s, aborting.", | 1301 | this.bar(f("No test file found in %s, terminating.", |
1293 | Array.prototype.slice.call(arguments)), "RED_BAR"); | 1302 | Array.prototype.slice.call(arguments)), "RED_BAR"); |
1294 | this.casper.exit(1); | 1303 | this.casper.exit(1); |
1295 | } | 1304 | } |
... | @@ -1324,6 +1333,20 @@ Tester.prototype.runTest = function runTest(testFile) { | ... | @@ -1324,6 +1333,20 @@ Tester.prototype.runTest = function runTest(testFile) { |
1324 | }; | 1333 | }; |
1325 | 1334 | ||
1326 | /** | 1335 | /** |
1336 | * Terminates current suite. | ||
1337 | * | ||
1338 | */ | ||
1339 | Tester.prototype.terminate = function(message) { | ||
1340 | "use strict"; | ||
1341 | if (message) { | ||
1342 | this.casper.warn(message); | ||
1343 | } | ||
1344 | this.done(); | ||
1345 | this.aborted = true; | ||
1346 | this.emit('tests.complete'); | ||
1347 | }; | ||
1348 | |||
1349 | /** | ||
1327 | * Saves results to file. | 1350 | * Saves results to file. |
1328 | * | 1351 | * |
1329 | * @param String filename Target file path. | 1352 | * @param String filename Target file path. | ... | ... |
-
Please register or sign in to post a comment