Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to debug nodeunit using node-inspector

I can do:

  • I can test node.js modules using nodeunit.
  • I can debug my node.js express site using node inspector.

But how to debug nodeunit test using node inspector?

I tried, but not working:

  • nodeunit --debug myNodeUnitModule_test.js It's not working.
  • I tried to install nodebug. And used it like this: 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:

  1. first load I see empty file list
  2. second load: page not found.

On my nodeunit test I wrote debugger to stop on debug there. But nothing.

like image 885
Maxim Yefremov Avatar asked May 20 '13 14:05

Maxim Yefremov


People also ask

How do I debug node scripts in Google Chrome dev tools?

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".


2 Answers

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

like image 31
Maxim Yefremov Avatar answered Oct 13 '22 17:10

Maxim Yefremov


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
like image 168
glukki Avatar answered Oct 13 '22 19:10

glukki