Commit 5ba5ae30 5ba5ae30b240772bbef425df3302c8990606f5d5 by Nicolas Perriault

fixes #722 - throw step errors are no more silenced

Introduced a new Casper `silentErrors` option which is set to `false`
by default.
1 parent 077bc3e9
...@@ -281,6 +281,17 @@ When this option is set to true — which is the default, any password informat ...@@ -281,6 +281,17 @@ When this option is set to true — which is the default, any password informat
281 281
282 .. index:: Step stack, timeout 282 .. index:: Step stack, timeout
283 283
284 ``silentErrors``
285 -------------------------------------------------------------------------------
286
287 **Type:** ``Boolean``
288
289 **Default:** ``false``
290
291 When this option is enabled, caught step errors are not thrown (though related events are still emitted). Mostly used internally in a testing context.
292
293 .. index:: timeout
294
284 ``stepTimeout`` 295 ``stepTimeout``
285 ------------------------------------------------------------------------------- 296 -------------------------------------------------------------------------------
286 297
......
...@@ -116,6 +116,7 @@ var Casper = function Casper(options) { ...@@ -116,6 +116,7 @@ var Casper = function Casper(options) {
116 userAgent: defaultUserAgent 116 userAgent: defaultUserAgent
117 }, 117 },
118 remoteScripts: [], 118 remoteScripts: [],
119 silentErrors: false,
119 stepTimeout: null, 120 stepTimeout: null,
120 timeout: null, 121 timeout: null,
121 verbose: false, 122 verbose: false,
...@@ -384,6 +385,9 @@ Casper.prototype.checkStep = function checkStep(self, onComplete) { ...@@ -384,6 +385,9 @@ Casper.prototype.checkStep = function checkStep(self, onComplete) {
384 } 385 }
385 } catch (error) { 386 } catch (error) {
386 self.emit('complete.error', error); 387 self.emit('complete.error', error);
388 if (!self.options.silentErrors) {
389 throw error;
390 }
387 } 391 }
388 }; 392 };
389 393
...@@ -1528,6 +1532,9 @@ Casper.prototype.runStep = function runStep(step) { ...@@ -1528,6 +1532,9 @@ Casper.prototype.runStep = function runStep(step) {
1528 } 1532 }
1529 } catch (err) { 1533 } catch (err) {
1530 this.emit('step.error', err); 1534 this.emit('step.error', err);
1535 if (!this.options.silentErrors) {
1536 throw err;
1537 }
1531 } 1538 }
1532 if (!skipLog) { 1539 if (!skipLog) {
1533 this.emit('step.complete', stepResult); 1540 this.emit('step.complete', stepResult);
...@@ -1981,6 +1988,9 @@ Casper.prototype.wait = function wait(timeout, then) { ...@@ -1981,6 +1988,9 @@ Casper.prototype.wait = function wait(timeout, then) {
1981 then.call(self, self); 1988 then.call(self, self);
1982 } catch (error) { 1989 } catch (error) {
1983 self.emit('wait.error', error); 1990 self.emit('wait.error', error);
1991 if (!self.options.silentErrors) {
1992 throw error;
1993 }
1984 } 1994 }
1985 } 1995 }
1986 self.waitDone(); 1996 self.waitDone();
...@@ -2044,6 +2054,9 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout, de ...@@ -2044,6 +2054,9 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout, de
2044 return onWaitTimeout.call(self, timeout, details); 2054 return onWaitTimeout.call(self, timeout, details);
2045 } catch (error) { 2055 } catch (error) {
2046 self.emit('waitFor.timeout.error', error); 2056 self.emit('waitFor.timeout.error', error);
2057 if (!self.options.silentErrors) {
2058 throw error;
2059 }
2047 } finally { 2060 } finally {
2048 return; 2061 return;
2049 } 2062 }
......
...@@ -13,7 +13,8 @@ var f = utils.format; ...@@ -13,7 +13,8 @@ var f = utils.format;
13 var loadIncludes = ['includes', 'pre', 'post']; 13 var loadIncludes = ['includes', 'pre', 'post'];
14 var tests = []; 14 var tests = [];
15 var casper = require('casper').create({ 15 var casper = require('casper').create({
16 exitOnError: false 16 exitOnError: false,
17 silentErrors: true // we subscribe to error events for catching them
17 }); 18 });
18 19
19 // local utils 20 // local utils
......