use node-inspector to debug mocha test in es6
See original GitHub issueI have a react app written in es6, and I’m using mocha to unit test it. For some reason, the unit test failed and I wanted to debug it to find out why.
- I first tried node-debug command
node-debug mocha test/.setup.js test/**/*-test.js
and node-inspector successfully stopped on _mocha, but after I insert breakpoints on my .setup.js, it never hit my break point and went straight to finish. So basically, it doesn’t work at all!
- I then tried run node-inspector in advanced mode, i.e. run node-inspector in a seperate shell, then start mocha in debug mode
shell 1: node-inspector
shell 2: mocha --debug-brk test/.setup.js test/**/*-test.js
and I have got it work! unbelievable! the only issue is performance, it took node-inspector a very long time (~5 minutes) to load the transpiled es5 scripts, and I once thought node-inspector has died (when attaching to node from vs code, it didn’t take that long! so it’s not a babel issue).
Question: why node-debug doesn’t work in my scenario , and why running in separate shell works, but take such a long time?
running environment
$ npm list -g node-inspector mocha-cli
C:\Users\admin\AppData\Roaming\npm
├── mocha-cli@1.0.1
└── node-inspector@0.12.8
$ npm list mocha
enzyme-example-mocha@0.1.0 d:\__work\enzyme-example-mocha
└── mocha@2.5.3
$ node -v
v4.4.6
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:5
I ended up using this:
to finally allow setting breakpoints in my code under Mocha testing. Switching to inspect debugging because:
This under Windows 10, node 7.7.4, mocha 3.3.0
@bochen2014 I ran into the same issue, I think it’s because bin/mocha spawns a sub-process which executes bin/_mocha
I found that out from this comment at the top of the bin/mocha file:
I was successful running it like so: