问题
I am using mocha to test my code. I am using node inspector to debug my code.
bash
mocha test/test.* --debug-brk
This works but not so well. It stops at the first line of code in mocha. I want it to stop it at my code. I tried using the 'debugger' key word to make a manual breakpoint but some how it does not stop there.
回答1:
Try placing a breakpoint at the bottom of the mocha library per this issue. For some reason that allows debugger
statements in your modules to pause the node debugger.
However it doesn't seem to stop at debugger statements in the spec itself. I have a SO question highlighting that problem.
回答2:
I was on the latest node version, using the node-debug command (to launch node-inspector and having the same issues you were. Here's what I'm rolling with currently:
Using the following versions:
- node: 0.11.13 (I downgraded from latest) <-- I specifically had to use this one
- mocha: 2.2.1 <-- might work with any
- node-inspector: 0.9.2 <-- might work with any
Start your tests using the following command:
- node-debug _mocha test/unit-tests.js
Navigate to your test file and start putting in breakpoints, then hit run. I usually put one up by the 'requires' of my test file, and several within my 'it' functions.
Hope that helps, and that one day this kind of thing will just work :P
Got the idea to downgrade node from here: https://www.bountysource.com/issues/7978672-script-is-resumed-as-soon-as-node-inspector-is-loaded
And the command from here: https://github.com/node-inspector/node-inspector#how-do-i-debug-mocha-unit-tests
来源:https://stackoverflow.com/questions/16760258/node-inspector-with-mocha-not-working-with-debugger-command