Commit 443a2647 443a26472cb16a35e3f96bfe7fd7b3f94acb0e6a by Nicolas Perriault

fixes #308, fixes #309 - proper module error backtraces

1 parent a918f248
......@@ -80,6 +80,7 @@ Also, `Casper.mouseEvent()` will now directly trigger an error on failure instea
### Bugfixes & enhancements
- fixed [#308](https://github.com/n1k0/casperjs/issues/308) & [#309](https://github.com/n1k0/casperjs/issues/309) - proper module error backtraces
- fixed [#306](https://github.com/n1k0/casperjs/issues/306) - Raise an explicit error on invalid test path
- fixed [#300](https://github.com/n1k0/casperjs/issues/300) - Ensure that `findOne()` and `findAll()` observe the scope for XPath expressions, not just when passed CSS selectors
- fixed [#294](https://github.com/n1k0/casperjs/issues/294) - Automatically fail test on any runtime error or timeout
......
......@@ -120,7 +120,7 @@ function patchRequire(require, requireDirs) {
}
}
if (!file) {
throw new Error("CasperJS couldn't find module " + path);
throw new window.CasperError("CasperJS couldn't find module " + path);
}
if (file in requireCache) {
return requireCache[file].exports;
......@@ -137,8 +137,14 @@ function patchRequire(require, requireDirs) {
try {
fn(file, _require, module, module.exports);
} catch (e) {
var error = new window.CasperError('__mod_error(' + path + '):: ' + e);
var error = new window.CasperError('__mod_error(' + path + ':' + e.line + '):: ' + e);
error.file = file;
error.line = e.line;
error.stack = e.stack;
error.stackArray = JSON.parse(JSON.stringify(e.stackArray));
if (error.stackArray.length > 0) {
error.stackArray[0].sourceURL = file;
}
throw error;
}
requireCache[file] = module;
......@@ -264,20 +270,21 @@ function bootstrap(global) {
*/
phantom.initCasperCli = function initCasperCli() {
var fs = require("fs");
var baseTestsPath = fs.pathJoin(phantom.casperPath, 'tests');
if (!!phantom.casperArgs.options.version) {
console.log(phantom.casperVersion.toString());
phantom.exit(0);
} else if (phantom.casperArgs.get(0) === "test") {
phantom.casperScript = fs.absolute(fs.pathJoin(phantom.casperPath, 'tests', 'run.js'));
phantom.casperScript = fs.absolute(fs.pathJoin(baseTestsPath, 'run.js'));
phantom.casperTest = true;
phantom.casperArgs.drop("test");
} else if (phantom.casperArgs.get(0) === "selftest") {
phantom.casperScript = fs.absolute(fs.pathJoin(phantom.casperPath, 'tests', 'run.js'));
phantom.casperSelfTest = true;
phantom.casperArgs.options.includes = fs.pathJoin(phantom.casperPath, 'tests', 'selftest.js');
phantom.casperScript = fs.absolute(fs.pathJoin(baseTestsPath, 'run.js'));
phantom.casperSelfTest = phantom.casperTest = true;
phantom.casperArgs.options.includes = fs.pathJoin(baseTestsPath, 'selftest.js');
if (phantom.casperArgs.args.length <= 1) {
phantom.casperArgs.args.push(fs.pathJoin(phantom.casperPath, 'tests', 'suites'));
phantom.casperArgs.args.push(fs.pathJoin(baseTestsPath, 'suites'));
}
phantom.casperArgs.drop("selftest");
} else if (phantom.casperArgs.args.length === 0 || !!phantom.casperArgs.options.help) {
......
......@@ -165,7 +165,6 @@ var Casper = function Casper(options) {
var notices = [];
if (match && match.length === 4) {
notices.push(' in module ' + match[2]);
notices.push(' NOTICE: errors within modules cannot be backtraced yet.');
msg = match[3];
}
console.error(c.colorize(msg, 'RED_BAR', 80));
......
......@@ -124,6 +124,9 @@ var Tester = function Tester(casper, options) {
// casper events
this.casper.on('error', function onCasperError(msg, backtrace) {
if (!phantom.casperTest) {
return;
}
var line = 0;
if (!utils.isString(msg) && msg.indexOf(this.SKIP_MESSAGE) === -1) {
try {
......