Commit b5935294 b5935294dcb134cd8dd7890ff96e084ef4ebf0c8 by Nicolas Perriault

Merge pull request #673 from nathanboktae/step-exception-bug

Exceptions thrown in steps causes casperjs to again throw and crash
2 parents 6efbbbde a603870d
......@@ -180,9 +180,6 @@ var Casper = function Casper(options) {
this.initErrorHandler();
this.on('error', function(msg, backtrace) {
if (/^(Assertion|Termination|TimedOut)Error/.test(msg)) {
return;
}
var c = this.getColorizer();
var match = /^(.*): __mod_error(.*):: (.*)/.exec(msg);
var notices = [];
......@@ -194,7 +191,7 @@ var Casper = function Casper(options) {
notices.forEach(function(notice) {
console.error(c.colorize(notice, 'COMMENT'));
});
backtrace.forEach(function(item) {
(backtrace || []).forEach(function(item) {
var message = fs.absolute(item.file) + ":" + c.colorize(item.line, "COMMENT");
if (item['function']) {
message += " in " + c.colorize(item['function'], "PARAMETER");
......@@ -387,7 +384,6 @@ Casper.prototype.checkStep = function checkStep(self, onComplete) {
}
} catch (error) {
self.emit('complete.error', error);
self.emit('error', error);
}
};
......@@ -1535,7 +1531,6 @@ Casper.prototype.runStep = function runStep(step) {
}
} catch (err) {
this.emit('step.error', err);
this.emit('error', err);
}
if (!skipLog) {
this.emit('step.complete', stepResult);
......
......@@ -269,6 +269,24 @@ class TestCommandOutputTest(CasperExecTestBase):
], failing=True)
@timeout(20)
def test_step_throwing_test(self):
# using begin()
script_path = os.path.join(TEST_ROOT, 'tester', 'step_throws.js')
self.assertCommandOutputContains('test ' + script_path, [
script_path,
'# step throws',
'FAIL Error: oops!',
'# type: uncaughtError',
'# file: %s:5' % script_path,
'# error: oops!',
'FAIL 1 test executed',
'0 passed',
'1 failed',
'0 dubious',
'0 skipped',
], failing=True)
@timeout(20)
def test_dubious_test(self):
script_path = os.path.join(TEST_ROOT, 'tester', 'dubious.js')
self.assertCommandOutputContains('test ' + script_path, [
......
/*jshint strict:false*/
casper.test.begin('step throws', 1, function(test) {
casper.start();
casper.then(function() {
throw new Error('oops!')
});
casper.run(function() {
test.done();
})
});