Commit 583d1e7b 583d1e7b33e2a62b6aa1a44f9ea7865f49458155 by Nicolas Perriault

better error handling

1 parent 82863faf
......@@ -5,3 +5,4 @@ modules/querystring.js
samples/**
tests/**
tmp
./*.js
......
......@@ -69,12 +69,16 @@ CasperError.prototype = Object.getPrototypeOf(new Error());
}
function __die(message) {
console.error(message);
if (message) {
console.error(message);
}
phantom.exit(1);
}
function __terminate(message) {
console.log(message);
if (message) {
console.log(message);
}
phantom.exit();
}
......@@ -90,13 +94,17 @@ CasperError.prototype = Object.getPrototypeOf(new Error());
}
})(phantom.version);
// Hooks in default phantomjs error handler to print a hint when a possible
// casperjs command misuse is detected.
// Hooks in default phantomjs error handler
phantom.onError = function onPhantomError(msg, trace) {
phantom.defaultErrorHandler.apply(phantom, arguments);
// print a hint when a possible casperjs command misuse is detected
if (msg.indexOf("ReferenceError: Can't find variable: casper") === 0) {
console.error('Hint: you may want to use the `casperjs test` command.');
}
// exits on syntax error
if (msg.indexOf('SyntaxError: Parse error') === 0) {
__die();
}
};
// Patching fs
......
......@@ -360,7 +360,6 @@ Casper.prototype.checkStep = function checkStep(self, onComplete) {
}
} catch (error) {
self.emit('complete.error', error);
throw error;
}
};
......@@ -1372,7 +1371,6 @@ Casper.prototype.runStep = function runStep(step) {
}
} catch (err) {
this.emit('step.error', err);
throw err;
}
if (!skipLog) {
this.emit('step.complete', stepResult);
......
......@@ -259,7 +259,7 @@ Tester.prototype.assertTrue = function assert(subject, message, context) {
}
}, context || {});
if (!result.success && result.doThrow) {
throw new AssertionError(message, result);
throw new AssertionError(message || result.standard, result);
}
return this.processAssertionResult(result);
};
......
qsfjdhf!èrè"èqwnfkmsghfkswjdgfjksn
......@@ -81,6 +81,20 @@ class CasperExecTest(unittest.TestCase):
self.assertCommandOutputEquals(script_path, 'it works')
@timeout(20)
def test_syntax_error(self):
script_path = os.path.join(TEST_ROOT, 'error', 'syntax.js')
self.assertCommandOutputContains(script_path, [
'SyntaxError: Parse error',
], failing=True)
@timeout(20)
def test_syntax_error_in_test(self):
script_path = os.path.join(TEST_ROOT, 'error', 'syntax.js')
self.assertCommandOutputContains('test %s' % script_path, [
'SyntaxError: Parse error',
], failing=True)
@timeout(20)
def test_simple_test_script(self):
script_path = os.path.join(TEST_ROOT, 'tester', 'mytest.js')
self.assertCommandOutputContains('test ' + script_path, [
......