Commit eb98da17 eb98da17607a04499bf8ba806db85dd702bd8b8d by Nicolas Perriault

refs #215 - attempting to fix `--fail-fast` again

1 parent 2f1993f1
...@@ -48,16 +48,19 @@ exports.create = function create(casper, options) { ...@@ -48,16 +48,19 @@ exports.create = function create(casper, options) {
48 */ 48 */
49 var Tester = function Tester(casper, options) { 49 var Tester = function Tester(casper, options) {
50 "use strict"; 50 "use strict";
51 /*jshint maxstatements:20*/ 51 /*jshint maxstatements:30*/
52 52
53 if (!utils.isCasperObject(casper)) { 53 if (!utils.isCasperObject(casper)) {
54 throw new CasperError("Tester needs a Casper instance"); 54 throw new CasperError("Tester needs a Casper instance");
55 } 55 }
56 56
57 var self = this;
58
57 this.casper = casper; 59 this.casper = casper;
58 60
59 this.SKIP_MESSAGE = '__termination__'; 61 this.SKIP_MESSAGE = '__termination__';
60 62
63 this.aborted = false;
61 this.executed = 0; 64 this.executed = 0;
62 this.currentTestFile = null; 65 this.currentTestFile = null;
63 this.currentSuiteNum = 0; 66 this.currentSuiteNum = 0;
...@@ -141,10 +144,10 @@ var Tester = function Tester(casper, options) { ...@@ -141,10 +144,10 @@ var Tester = function Tester(casper, options) {
141 if (!phantom.casperTest) { 144 if (!phantom.casperTest) {
142 return; 145 return;
143 } 146 }
144 if (msg === this.test.SKIP_MESSAGE) { 147 if (msg === self.SKIP_MESSAGE) {
145 this.warn(f('--fail-fast: aborted remaining tests in "%s"', this.test.currentTestFile)); 148 this.warn(f('--fail-fast: aborted remaining tests in "%s"', self.currentTestFile));
146 this.test.currentSuiteNum++; 149 self.aborted = true;
147 return this.test.done(); 150 return self.done();
148 } 151 }
149 var line = 0; 152 var line = 0;
150 if (!utils.isString(msg)) { 153 if (!utils.isString(msg)) {
...@@ -152,15 +155,15 @@ var Tester = function Tester(casper, options) { ...@@ -152,15 +155,15 @@ var Tester = function Tester(casper, options) {
152 line = backtrace[0].line; 155 line = backtrace[0].line;
153 } catch (e) {} 156 } catch (e) {}
154 } 157 }
155 this.test.uncaughtError(msg, this.test.currentTestFile, line); 158 self.uncaughtError(msg, self.currentTestFile, line);
156 this.test.done(); 159 self.done();
157 }); 160 });
158 161
159 this.casper.on('step.error', function onStepError(e) { 162 this.casper.on('step.error', function onStepError(e) {
160 if (e.message !== this.test.SKIP_MESSAGE) { 163 if (e.message !== self.SKIP_MESSAGE) {
161 this.test.uncaughtError(e, this.test.currentTestFile); 164 self.uncaughtError(e, self.currentTestFile);
162 } 165 }
163 this.test.done(); 166 self.done();
164 }); 167 });
165 }; 168 };
166 169
...@@ -1076,10 +1079,11 @@ Tester.prototype.runSuites = function runSuites() { ...@@ -1076,10 +1079,11 @@ Tester.prototype.runSuites = function runSuites() {
1076 if (self.running) { 1079 if (self.running) {
1077 return; 1080 return;
1078 } 1081 }
1079 if (self.currentSuiteNum === testFiles.length) { 1082 if (self.currentSuiteNum === testFiles.length || self.aborted) {
1080 self.emit('tests.complete'); 1083 self.emit('tests.complete');
1081 clearInterval(interval); 1084 clearInterval(interval);
1082 self.exporter.setSuiteDuration(self.calculateSuiteDuration()); 1085 self.exporter.setSuiteDuration(self.calculateSuiteDuration());
1086 self.aborted = false;
1083 } else { 1087 } else {
1084 self.runTest(testFiles[self.currentSuiteNum]); 1088 self.runTest(testFiles[self.currentSuiteNum]);
1085 self.exporter.setSuiteDuration(self.calculateSuiteDuration()); 1089 self.exporter.setSuiteDuration(self.calculateSuiteDuration());
......