question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

use node-inspector to debug mocha test in es6

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

2reactions
tshinniccommented, May 3, 2017

I ended up using this:

node  --inspect-brk  node_modules\mocha\bin\_mocha  --no-timeouts  test\TableGdef01.js

to finally allow setting breakpoints in my code under Mocha testing. Switching to inspect debugging because:

(node:6208) DeprecationWarning: node --debug is deprecated. Please use node --inspect instead. 

This under Windows 10, node 7.7.4, mocha 3.3.0

1reaction
MagicDuckcommented, Mar 21, 2017

@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:

/**
 * This tiny wrapper file checks for known node flags and appends them
 * when found, before invoking the "real" _mocha(1) executable.
 */

I was successful running it like so:

node-debug _mocha test --recursive --watch
Read more comments on GitHub >

github_iconTop Results From Across the Web

Debugg ES6 Mocha tests with node-debugger - Stack Overflow
I have a ES6 Babel project set up and everything is working fine. I run my tests using Mocha. Now I want to...
Read more >
Visual Debugging with ES6 and Node.js | by Alon Salant
To debug with node-inspector you: Start your app with the debugger enabled; Start the node-inspector server; Open the node-inspector UI in Chrome; Use...
Read more >
Debugging Mocha from Node using Chrome Inspector
How to debug Mocha tests running in Node using Chrome DevTools inspector. If you are using Mocha test runner, you can easily debug...
Read more >
Debugging mocha tests in a Docker container using Visual ...
In the end, I was debugging my mocha tests using WebStorm and node-inspector inside the containers and got stuff running. As I have...
Read more >
Debugging ES6 Mocha unit tests using VS Code - yer.ac
Typically in the past all my JS unit tests have been debuggable in-browser using DevTools, but with Mocha this is not the case...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found