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 ...@@ -80,6 +80,7 @@ Also, `Casper.mouseEvent()` will now directly trigger an error on failure instea
80 80
81 ### Bugfixes & enhancements 81 ### Bugfixes & enhancements
82 82
83 - fixed [#308](https://github.com/n1k0/casperjs/issues/308) & [#309](https://github.com/n1k0/casperjs/issues/309) - proper module error backtraces
83 - fixed [#306](https://github.com/n1k0/casperjs/issues/306) - Raise an explicit error on invalid test path 84 - fixed [#306](https://github.com/n1k0/casperjs/issues/306) - Raise an explicit error on invalid test path
84 - 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 85 - 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
85 - fixed [#294](https://github.com/n1k0/casperjs/issues/294) - Automatically fail test on any runtime error or timeout 86 - 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) { ...@@ -120,7 +120,7 @@ function patchRequire(require, requireDirs) {
120 } 120 }
121 } 121 }
122 if (!file) { 122 if (!file) {
123 throw new Error("CasperJS couldn't find module " + path); 123 throw new window.CasperError("CasperJS couldn't find module " + path);
124 } 124 }
125 if (file in requireCache) { 125 if (file in requireCache) {
126 return requireCache[file].exports; 126 return requireCache[file].exports;
...@@ -137,8 +137,14 @@ function patchRequire(require, requireDirs) { ...@@ -137,8 +137,14 @@ function patchRequire(require, requireDirs) {
137 try { 137 try {
138 fn(file, _require, module, module.exports); 138 fn(file, _require, module, module.exports);
139 } catch (e) { 139 } catch (e) {
140 var error = new window.CasperError('__mod_error(' + path + '):: ' + e); 140 var error = new window.CasperError('__mod_error(' + path + ':' + e.line + '):: ' + e);
141 error.file = file; 141 error.file = file;
142 error.line = e.line;
143 error.stack = e.stack;
144 error.stackArray = JSON.parse(JSON.stringify(e.stackArray));
145 if (error.stackArray.length > 0) {
146 error.stackArray[0].sourceURL = file;
147 }
142 throw error; 148 throw error;
143 } 149 }
144 requireCache[file] = module; 150 requireCache[file] = module;
...@@ -264,20 +270,21 @@ function bootstrap(global) { ...@@ -264,20 +270,21 @@ function bootstrap(global) {
264 */ 270 */
265 phantom.initCasperCli = function initCasperCli() { 271 phantom.initCasperCli = function initCasperCli() {
266 var fs = require("fs"); 272 var fs = require("fs");
273 var baseTestsPath = fs.pathJoin(phantom.casperPath, 'tests');
267 274
268 if (!!phantom.casperArgs.options.version) { 275 if (!!phantom.casperArgs.options.version) {
269 console.log(phantom.casperVersion.toString()); 276 console.log(phantom.casperVersion.toString());
270 phantom.exit(0); 277 phantom.exit(0);
271 } else if (phantom.casperArgs.get(0) === "test") { 278 } else if (phantom.casperArgs.get(0) === "test") {
272 phantom.casperScript = fs.absolute(fs.pathJoin(phantom.casperPath, 'tests', 'run.js')); 279 phantom.casperScript = fs.absolute(fs.pathJoin(baseTestsPath, 'run.js'));
273 phantom.casperTest = true; 280 phantom.casperTest = true;
274 phantom.casperArgs.drop("test"); 281 phantom.casperArgs.drop("test");
275 } else if (phantom.casperArgs.get(0) === "selftest") { 282 } else if (phantom.casperArgs.get(0) === "selftest") {
276 phantom.casperScript = fs.absolute(fs.pathJoin(phantom.casperPath, 'tests', 'run.js')); 283 phantom.casperScript = fs.absolute(fs.pathJoin(baseTestsPath, 'run.js'));
277 phantom.casperSelfTest = true; 284 phantom.casperSelfTest = phantom.casperTest = true;
278 phantom.casperArgs.options.includes = fs.pathJoin(phantom.casperPath, 'tests', 'selftest.js'); 285 phantom.casperArgs.options.includes = fs.pathJoin(baseTestsPath, 'selftest.js');
279 if (phantom.casperArgs.args.length <= 1) { 286 if (phantom.casperArgs.args.length <= 1) {
280 phantom.casperArgs.args.push(fs.pathJoin(phantom.casperPath, 'tests', 'suites')); 287 phantom.casperArgs.args.push(fs.pathJoin(baseTestsPath, 'suites'));
281 } 288 }
282 phantom.casperArgs.drop("selftest"); 289 phantom.casperArgs.drop("selftest");
283 } else if (phantom.casperArgs.args.length === 0 || !!phantom.casperArgs.options.help) { 290 } else if (phantom.casperArgs.args.length === 0 || !!phantom.casperArgs.options.help) {
......
...@@ -165,7 +165,6 @@ var Casper = function Casper(options) { ...@@ -165,7 +165,6 @@ var Casper = function Casper(options) {
165 var notices = []; 165 var notices = [];
166 if (match && match.length === 4) { 166 if (match && match.length === 4) {
167 notices.push(' in module ' + match[2]); 167 notices.push(' in module ' + match[2]);
168 notices.push(' NOTICE: errors within modules cannot be backtraced yet.');
169 msg = match[3]; 168 msg = match[3];
170 } 169 }
171 console.error(c.colorize(msg, 'RED_BAR', 80)); 170 console.error(c.colorize(msg, 'RED_BAR', 80));
......
...@@ -124,6 +124,9 @@ var Tester = function Tester(casper, options) { ...@@ -124,6 +124,9 @@ var Tester = function Tester(casper, options) {
124 124
125 // casper events 125 // casper events
126 this.casper.on('error', function onCasperError(msg, backtrace) { 126 this.casper.on('error', function onCasperError(msg, backtrace) {
127 if (!phantom.casperTest) {
128 return;
129 }
127 var line = 0; 130 var line = 0;
128 if (!utils.isString(msg) && msg.indexOf(this.SKIP_MESSAGE) === -1) { 131 if (!utils.isString(msg) && msg.indexOf(this.SKIP_MESSAGE) === -1) {
129 try { 132 try {
......