I can do:
But how to debug nodeunit test using node inspector?
I tried, but not working:
nodeunit --debug myNodeUnitModule_test.js
It's not working.nodebug /usr/local/bin/nodeunit myNodeunit_test.js
But it's not working neither on ubuntu (No such file or directory
) nor on mac (env: node\r: No such file or directory
)Almost works node --debug /usr/local/bin/nodeunit ./routes/edit/bodyTelInfoArraysToObject_test.js
where /usr/local/bin/nodeunit
is path taken by command which nodeunit
got output:
debugger listening on port 5858
and test executed there.
But I can't jump in debuggin: when I open url localhost:8080
in chrome to watch debugging:
On my nodeunit test I wrote debugger
to stop on debug there.
But nothing.
Use Chrome DevTools Once your Node. js app is registered as remote target and listening for debuggers, you can open the webpage chrome://inspect/#devices in Google Chrome to see the dedicated DevTools for Node. By default, the DevTools try to discover targets on "127.0. 0.1:9229".
Solution found:
in console: node --debug-brk `which nodeunit` ./path/To/My/NodeUnitTests/nodeunit_test.coffee (Attention: `which nodeunit` is in back quotes)
in another console:
node-inspector &
And in google chrome open: http://0.0.0.0:8080/debug?port=5858
Here I see nodeunit debuging from the start. Click continue execution several times in browser until jump to nodeunit test, where I have debugger;
string. So I debugging my nodeunit test with nodeinspector
In your tests insert debugger;
command
exports['Main test'] = function(test){
debugger;
test.expect(1);
test.ok(true, 'Must be ok');
test.done();
};
And start all this
$ node --debug-brk `which nodeunit` test.js
Now in browser press F8, then F10, and you are right on the next line after first debugger;
command in your test.
But I prefer to start everything with node-supervisor, that restart test automatically when test finished or files in project directory changed:
$ npm -g install supervisor node-inspector
$ # console 1
$ # supervisor restarts node-inspector when it quits
$ # ignores file changes
$ supervisor -i . -x node-inspector .
$ # console 2
$ supervisor --debug-brk -- `which nodeunit` test/index.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With