Commit 3eb1fc00 3eb1fc00d14a2d075932f031b07aaafe6a095657 by Nicolas Perriault

fixes #249 - default timeout functions don't die() anymore in tests

Also, a new `onWaitTimeout` option has been added in order to set
a desired behavior when a `wait*` function times out.
1 parent a4715333
......@@ -8,7 +8,8 @@ This version is yet to be released.
### Important Changes & Caveats
**BC BREAK**: - fixes [#220](https://github.com/n1k0/casperjs/issues/220), [#237](https://github.com/n1k0/casperjs/issues/237) - added a `waitTimeout` options, removed `defaultWaitTimeout` option.
**BC BREAK**: fixes [#220](https://github.com/n1k0/casperjs/issues/220), [#237](https://github.com/n1k0/casperjs/issues/237) - added a `waitTimeout` options, removed `defaultWaitTimeout` option.
**BC BREAK** (for the better): fixes [#249](https://github.com/n1k0/casperjs/issues/249) - default timeout functions don't `die()` anymore in tests
**BC BREAK** (for the better): merged [#188](https://github.com/n1k0/casperjs/issues/188) - Easy access to current response object;
You can now access the current response object as the first parameter of step callbacks:
......@@ -64,6 +65,7 @@ The documentation has been [updated accordingly](http://casperjs.org/api.html#ca
### Bugfixes & enhancements
- a new `onWaitTimeout` option has been added, to allow defining a default behavior when a `waitFor*` function times out.
- [Casper.resourceExists()](http://casperjs.org/api.html#casper.resourceExists) and related functions now checks for non HTTP-404 received responses.
- closes [#205](https://github.com/n1k0/casperjs/issues/205) - [`debugHTML()`](http://casperjs.org/api.html#casper.debugHTML) can have a selector passed; added [`getHTML()`](http://casperjs.org/api.html#casper.getHTML)
- closes [#230](https://github.com/n1k0/casperjs/issues/230) - added [`ClientUtils.getElementsBound()`](http://casperjs.org/api.html#clientutils.getElementsBounds) and [`Casper.getElementsBound()`](http://casperjs.org/api.html#casper.getElementsBounds)
......
......@@ -94,8 +94,15 @@ var Casper = function Casper(options) {
onResourceReceived: null,
onResourceRequested: null,
onStepComplete: null,
onStepTimeout: null,
onTimeout: null,
onStepTimeout: function _onStepTimeout(timeout, stepNum) {
this.die("Maximum step execution timeout exceeded for step " + stepNum);
},
onTimeout: function _onTimeout(timeout) {
this.die(f("Script timeout of %dms reached, exiting.", timeout));
},
onWaitTimeout: function _onWaitTimeout(timeout) {
this.die(f("Wait timeout of %dms expired, exiting.", timeout));
},
page: null,
pageSettings: {
localToRemoteUrlAccessEnabled: true,
......@@ -556,12 +563,14 @@ Casper.prototype.evaluate = function evaluate(fn, context) {
*
* @param function fn The expression to evaluate
* @param String message The error message to log
* @param Number status An optional exit status code (must be > 0)
*
* @return Casper
*/
Casper.prototype.evaluateOrDie = function evaluateOrDie(fn, message) {
Casper.prototype.evaluateOrDie = function evaluateOrDie(fn, message, status) {
"use strict";
if (!this.evaluate(fn)) {
return this.die(message);
return this.die(message, status);
}
return this;
};
......@@ -1139,9 +1148,7 @@ Casper.prototype.runStep = function runStep(step) {
if ((self.test.currentSuiteNum + "-" + self.step) === stepNum) {
self.emit('step.timeout');
if (utils.isFunction(self.options.onStepTimeout)) {
self.options.onStepTimeout.call(self, self);
} else {
self.die("Maximum step execution timeout exceeded for step " + stepNum, "error");
self.options.onStepTimeout.call(self, self.options.onStepTimeout, stepNum);
}
}
clearInterval(stepTimeoutCheckInterval);
......@@ -1223,9 +1230,7 @@ Casper.prototype.start = function start(location, then) {
setTimeout(function _check(self) {
self.emit('timeout');
if (utils.isFunction(self.options.onTimeout)) {
self.options.onTimeout.call(self, self);
} else {
self.die(f("Timeout of %dms exceeded, exiting.", self.options.timeout));
self.options.onTimeout.call(self, self.options.timeout);
}
}, this.options.timeout, this);
}
......@@ -1510,11 +1515,11 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout) {
if (!condition) {
self.log("Casper.waitFor() timeout", "warning");
self.emit('waitFor.timeout');
if (utils.isFunction(onTimeout)) {
onTimeout.call(self, self);
} else {
self.die(f("Timeout of %dms expired, exiting.", timeout), "error");
var onWaitTimeout = onTimeout ? onTimeout : self.options.onWaitTimeout;
if (!utils.isFunction(onWaitTimeout)) {
throw new CasperError('Invalid timeout function, exiting.');
}
onWaitTimeout.call(self, timeout);
} else {
self.log(f("waitFor() finished in %dms.", new Date().getTime() - start), "info");
if (then) {
......
......@@ -77,6 +77,19 @@ var Tester = function Tester(casper, options) {
failures: []
};
// specific timeout callbacks
casper.options.onStepTimeout = function test_onStepTimeout(timeout) {
this.test.fail(f("Step timeout occured (%dms)", timeout));
};
casper.options.onTimeout = function test_onTimeout(timeout) {
this.test.fail(f("Timeout occured (%dms)", timeout));
};
casper.options.onWaitTimeout = function test_onWaitTimeout(timeout) {
this.test.fail(f("Wait timeout occured (%dms)", timeout));
};
// events
casper.on('error', function(msg, backtrace) {
var line = 0;
......