nathanboktae / mocha-casperjs

Write CasperJS tests using Mocha
MIT License
120 stars 30 forks source link

Error reporting and rewire #73

Closed maxkoryukov closed 8 years ago

maxkoryukov commented 8 years ago

Hello!

Shortly

mocha-casperjs

  1. doesn't show actual error (or there is not enough debug information)
  2. doesn't work with rewire ( https://github.com/jhnns/rewire )

    Detailed

I have very simple test/test.js file:

var rewire = require('rewire');

yes, there is just one line of javascript.

But when I try to run tests, I get:

user@host ~/projects/ep-js $ mocha-casperjs 
SyntaxError: Parse error                                                        
TypeError: 'undefined' is not an object (evaluating 'currentTest.errors')       
  /usr/lib/node_modules/mocha-casperjs/mocha-casperjs.js:18
  /usr/lib/node_modules/mocha-casperjs/mocha-casperjs.js:46
  /usr/lib/node_modules/casperjs/modules/events.js:104 in emit
  /usr/lib/node_modules/casperjs/modules/casper.js:1213 in phantom_onError
  /home/user/projects/ep-js/phantomjs:/bootstrap.js:58
CasperError: Can't find module /home/user/projects/ep-js/test/test   
  /usr/lib/node_modules/casperjs/bin/bootstrap.js:262 in patchedRequire
  /usr/lib/node_modules/mocha-casperjs/bin/cli.js:185
TypeError: 'undefined' is not an object (evaluating 'currentTest.errors')       
  /usr/lib/node_modules/mocha-casperjs/mocha-casperjs.js:18
  /usr/lib/node_modules/mocha-casperjs/mocha-casperjs.js:46
  /usr/lib/node_modules/casperjs/modules/events.js:104 in emit
  /usr/lib/node_modules/casperjs/modules/casper.js:1213 in phantom_onError
  /home/user/projects/ep-js/phantomjs:/bootstrap.js:58

selection_015

nathanboktae commented 8 years ago

mocha-casperjs runs in phantomjs, not Node.js. There is 0 node.js code in this project - it just uses npm as a distribution mechanism. phantomjs supports the CommonJS module format, but modules can't use any node specifics. Looking at the rewire project, it's very node-specific so it won't work.

From the errors I can see something failed to parse and a module failed to load. I guess casper is interpretting the parse error as a 'Can't find module error.' Not the clearest error, but phantom might not be giving it much more information.

maxkoryukov commented 8 years ago

Thanks, I got it;)

But anyway: the error reporting is watery, there is no line numbers or other info. It's sad... I think, it is no sense to open this ticket;)

Thanks!

nathanboktae commented 8 years ago

Yeah I'm not sure why you didn't get a stack trace line in your code (I reproduced the same thing myself), but I'm at the mercy of phantomjs and casperjs here. An actual test failure trace is much better (note phantomjs doesn't support source maps).