21

I can't seem to debug mocha scripts.

I am able to run node with inspector like this node --inspect script.js. This then gives me a url to go to to debug, something like chrome-devtools://devtools/remote/...

However, when I use mocha with this line mocha --inspect test.js I am not able to debug. It says 'Debugger listening on [::]:5858'. Is there any way for me to debug a mocha test using node's inspector?

Going to localhost:5858 gives me this info:

Type: connect
V8-Version: 5.1.281.84
Protocol-Version: 1
Embedding-Host: node v6.9.1
Content-Length: 0

Using --inspect --debug-brk doesn't help.

Elliot
  • 1,893
  • 4
  • 17
  • 35
  • using `node-inspector` might work. But node native `--inspect` is definitely better. Waiting for a solution – Boyang Dec 08 '16 at 11:23
  • 1
    Try with `node --inspect --debug-brk script.js`: this should set a breakpoint at the first line of the script, giving you time to open the DevTools panel. – MarcoL Dec 08 '16 at 15:24
  • @MarcoL Tried --debug-brk but doesn't solve the problem. – Elliot Dec 08 '16 at 15:27
  • Did you copy and paste that URL (`chrome-devtools-etc...`) in the browser? – MarcoL Dec 08 '16 at 15:28
  • 1
    This is awesome. Testing is so cutting edge that we don't need an inspector. Don't you miss PHP-style debugging with echo and print all over the place? This is progress! – Rolf Nov 08 '17 at 09:11

2 Answers2

26

The problem was my version of mocha. I was running a version older than 3.1.0. --inspect support was added in 3.1.0

I am now able to run with debugging with these lines:

mocha --reporter spec --inspect test.js
mocha --reporter spec --inspect-brk test.js
Elliot
  • 1,893
  • 4
  • 17
  • 35
4

[DEP0062] DeprecationWarning: node --inspect --debug-brk is deprecated. Please use node --inspect-brk instead.

use in the future

mocha --reporter spec --inspect-brk test.js
mjabadilla
  • 1,006
  • 14
  • 31