Commit ca0604c8 ca0604c8b5da339ccdda12142ac0cdf29cdd1e2e by Nicolas Perriault

fixed #404 - --fail-fast option was broken

1 parent dc87cc13
...@@ -144,16 +144,7 @@ var Tester = function Tester(casper, options) { ...@@ -144,16 +144,7 @@ var Tester = function Tester(casper, options) {
144 144
145 // casper events 145 // casper events
146 this.casper.on('error', function onCasperError(msg, backtrace) { 146 this.casper.on('error', function onCasperError(msg, backtrace) {
147 if (/^AssertionError/.test(msg)) { 147 self.processPhantomError(msg, backtrace);
148 return;
149 }
150 this.test.fail(msg, {
151 type: "error",
152 doThrow: false,
153 values: {
154 stack: backtrace
155 }
156 });
157 }); 148 });
158 149
159 this.casper.on('waitFor.timeout', function onWaitForTimeout(timeout) { 150 this.casper.on('waitFor.timeout', function onWaitForTimeout(timeout) {
...@@ -165,13 +156,11 @@ var Tester = function Tester(casper, options) { ...@@ -165,13 +156,11 @@ var Tester = function Tester(casper, options) {
165 self.processError(error); 156 self.processError(error);
166 return self.done(); 157 return self.done();
167 } 158 }
168 if (error.indexOf('AssertionError') === 0) { 159 if (utils.isString(error) && error.indexOf('AssertionError') === 0) {
169 return; 160 return;
170 } 161 }
171 if (error === self.SKIP_MESSAGE) { 162 if (error === self.SKIP_MESSAGE) {
172 casper.warn(f('--fail-fast: aborted remaining tests in "%s"', self.currentTestFile)); 163 return self.abort('--fail-fast: aborted all remaining tests');
173 self.aborted = true;
174 return self.done();
175 } 164 }
176 var line = 0; 165 var line = 0;
177 try { 166 try {
...@@ -216,6 +205,18 @@ utils.inherits(Tester, events.EventEmitter); ...@@ -216,6 +205,18 @@ utils.inherits(Tester, events.EventEmitter);
216 exports.Tester = Tester; 205 exports.Tester = Tester;
217 206
218 /** 207 /**
208 * Aborts current test suite.
209 *
210 * @param {String} message Warning message (optional)
211 */
212 Tester.prototype.abort = function abort(message) {
213 "use strict";
214 this.aborted = true;
215 this.casper.warn(message || 'test suite aborted');
216 this.done();
217 };
218
219 /**
219 * Asserts that a condition strictly resolves to true. Also returns an 220 * Asserts that a condition strictly resolves to true. Also returns an
220 * "assertion object" containing useful informations about the test case 221 * "assertion object" containing useful informations about the test case
221 * results. 222 * results.
...@@ -1091,16 +1092,6 @@ Tester.prototype.pass = function pass(message) { ...@@ -1091,16 +1092,6 @@ Tester.prototype.pass = function pass(message) {
1091 }); 1092 });
1092 }; 1093 };
1093 1094
1094 Tester.prototype.prepare = function prepare(config) {
1095 "use strict";
1096 if (!utils.isObject(config)) {
1097 throw new CasperError('prepare() needs a config object');
1098 }
1099 if ('setUp' in config) {
1100
1101 }
1102 };
1103
1104 /** 1095 /**
1105 * Processes an assertion error. 1096 * Processes an assertion error.
1106 * 1097 *
...@@ -1108,7 +1099,7 @@ Tester.prototype.prepare = function prepare(config) { ...@@ -1108,7 +1099,7 @@ Tester.prototype.prepare = function prepare(config) {
1108 */ 1099 */
1109 Tester.prototype.processAssertionError = function(error) { 1100 Tester.prototype.processAssertionError = function(error) {
1110 "use strict"; 1101 "use strict";
1111 var result = error && error.result, 1102 var result = error && error.result || {},
1112 testFile = this.currentTestFile, 1103 testFile = this.currentTestFile,
1113 stackEntry; 1104 stackEntry;
1114 try { 1105 try {
...@@ -1175,6 +1166,31 @@ Tester.prototype.processError = function processError(error) { ...@@ -1175,6 +1166,31 @@ Tester.prototype.processError = function processError(error) {
1175 }; 1166 };
1176 1167
1177 /** 1168 /**
1169 * Processes a PhantomJS error, which is an error message and a backtrace.
1170 *
1171 * @param {String} message
1172 * @param {Array} backtrace
1173 */
1174 Tester.prototype.processPhantomError = function processPhantomError(msg, backtrace) {
1175 "use strict";
1176 if (/^AssertionError/.test(msg)) {
1177 this.casper.warn('looks you did not use begin() which is mandatory since 1.1');
1178 }
1179 if (msg === this.SKIP_MESSAGE) {
1180 return this.abort('--fail-fast: aborted all remaining tests');
1181 }
1182 this.fail(msg, {
1183 type: "error",
1184 doThrow: false,
1185 values: {
1186 error: msg,
1187 stack: backtrace
1188 }
1189 });
1190 this.done();
1191 };
1192
1193 /**
1178 * Renders a detailed report for each failed test. 1194 * Renders a detailed report for each failed test.
1179 * 1195 *
1180 */ 1196 */
......
1 /*global casper*/ 1 /*global casper*/
2 /*jshint strict:false maxstatements:99*/ 2 /*jshint strict:false, maxstatements:99*/
3 var utils = require('utils'), 3 var utils = require('utils'),
4 t = casper.test, 4 t = casper.test,
5 x = require('casper').selectXPath; 5 x = require('casper').selectXPath;
......