how to debug nodeunit using node-inspector

ぃ、小莉子 提交于 2019-12-03 02:41:25

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!