what's the least resistance path to debugging mocha tests? what's the least resistance path to debugging mocha tests? node.js node.js

what's the least resistance path to debugging mocha tests?


Edit, years later: the shortest path in Node 6+ is: mocha --debug-brk --inspect ./test.js coupled with the Node Inspector Manager plugin.

Many weeks later, no answers. Here's the quickest path that I found.

  1. write mocha tests
  2. install node-inspector
  3. start node-inspector -- it will now be listening on 5858
  4. start the mocha test with --debug-brk
  5. at this point the mocha test is paused on the first line
  6. open a web browser and go to localhost:5858
  7. (optional: add a debugger line at the top of your test file, set breakpoints after it stops in that file)
  8. hit F10 to get the code to go
  9. node-inspector will stop on any line that has debugger on it. Occasionally it won't move the code file's window to the right place, so you'll have to hit F10 to get it to step to the next line and show where it's at in the file.

Command line:

node-inspector & mocha --compilers coffee:coffee-script/register ./test/appTests.coffee --ui bdd -d -g "should X then Y" --debug-brk


In addition to @jcollum's answer above, I have found instead of using the --debug-brk flag, it is better to just use the --debug flag with -w (watch)

That way, when you add and remove debugger lines from your code, mocha will reload the tests automatically and your node-inspector will pause on the appropriate line.

This saves having to revisit the terminal constantly restarting the tests, then needlessly hitting "continue" in the debugger to get past the first line of the source.


With the latest versions of Mocha and node-inspector, this has been working great for me:

$ node-debug ./node_modules/mocha/bin/_mocha

It loads up the local Mocha executable as the debugged process, stopping on the first line for you to set up your breakpoints.