Commit 8c7d533f 8c7d533fb27dfa66f2c51906bd73d28d80c7494c by Nicolas Perriault

refs #369 - fixing asserts not performed on wait timeout

1 parent edfade4b
...@@ -1765,8 +1765,8 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout) { ...@@ -1765,8 +1765,8 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout) {
1765 self.waitDone(); 1765 self.waitDone();
1766 if (!condition) { 1766 if (!condition) {
1767 self.log("Casper.waitFor() timeout", "warning"); 1767 self.log("Casper.waitFor() timeout", "warning");
1768 self.emit('waitFor.timeout');
1769 var onWaitTimeout = onTimeout ? onTimeout : self.options.onWaitTimeout; 1768 var onWaitTimeout = onTimeout ? onTimeout : self.options.onWaitTimeout;
1769 self.emit('waitFor.timeout', timeout, onWaitTimeout);
1770 if (!utils.isFunction(onWaitTimeout)) { 1770 if (!utils.isFunction(onWaitTimeout)) {
1771 throw new CasperError('Invalid timeout function, exiting.'); 1771 throw new CasperError('Invalid timeout function, exiting.');
1772 } 1772 }
......
...@@ -143,7 +143,17 @@ var Tester = function Tester(casper, options) { ...@@ -143,7 +143,17 @@ var Tester = function Tester(casper, options) {
143 143
144 // casper events 144 // casper events
145 this.casper.on('error', function onCasperError(msg, backtrace) { 145 this.casper.on('error', function onCasperError(msg, backtrace) {
146 this.test.fail(msg, {
147 type: 'error',
148 doThrow: false,
149 values: {
150 stack: backtrace
151 }
152 });
153 });
146 154
155 this.casper.on('waitFor.timeout', function onWaitForTimeout(timeout) {
156 this.warn(f('wait timeout of %dms reached', timeout));
147 }); 157 });
148 158
149 function errorHandler(error, backtrace) { 159 function errorHandler(error, backtrace) {
...@@ -186,10 +196,6 @@ var Tester = function Tester(casper, options) { ...@@ -186,10 +196,6 @@ var Tester = function Tester(casper, options) {
186 return; 196 return;
187 } 197 }
188 198
189 // onRunComplete
190 this.casper.options.onRunComplete = function test_onRunComplete(casper) {
191 };
192
193 // specific timeout callbacks 199 // specific timeout callbacks
194 this.casper.options.onStepTimeout = function test_onStepTimeout(timeout, step) { 200 this.casper.options.onStepTimeout = function test_onStepTimeout(timeout, step) {
195 throw new TimedOutError(f("Step timeout occured at step %s (%dms)", step, timeout)); 201 throw new TimedOutError(f("Step timeout occured at step %s (%dms)", step, timeout));
...@@ -235,11 +241,12 @@ Tester.prototype.assertTrue = function assert(subject, message, context) { ...@@ -235,11 +241,12 @@ Tester.prototype.assertTrue = function assert(subject, message, context) {
235 standard: "Subject is strictly true", 241 standard: "Subject is strictly true",
236 message: message, 242 message: message,
237 file: this.currentTestFile, 243 file: this.currentTestFile,
244 doThrow: true,
238 values: { 245 values: {
239 subject: utils.getPropertyPath(context, 'values.subject') || subject 246 subject: utils.getPropertyPath(context, 'values.subject') || subject
240 } 247 }
241 }, context || {}); 248 }, context || {});
242 if (!result.success) { 249 if (!result.success && result.doThrow) {
243 throw new AssertionError(message, result); 250 throw new AssertionError(message, result);
244 } 251 }
245 return this.processAssertionResult(result); 252 return this.processAssertionResult(result);
...@@ -970,13 +977,15 @@ Tester.prototype.exec = function exec(file) { ...@@ -970,13 +977,15 @@ Tester.prototype.exec = function exec(file) {
970 * Adds a failed test entry to the stack. 977 * Adds a failed test entry to the stack.
971 * 978 *
972 * @param String message 979 * @param String message
980 * @param Object Failure context (optional)
973 */ 981 */
974 Tester.prototype.fail = function fail(message) { 982 Tester.prototype.fail = function fail(message, context) {
975 "use strict"; 983 "use strict";
976 return this.assert(false, message, { 984 context = context || {};
985 return this.assert(false, message, utils.mergeObjects({
977 type: "fail", 986 type: "fail",
978 standard: "explicit call to fail()" 987 standard: "explicit call to fail()"
979 }); 988 }, context));
980 }; 989 };
981 990
982 /** 991 /**
......