问题
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:
- first load I see empty file list
- second load: page not found.
On my nodeunit test I wrote debugger
to stop on debug there.
But nothing.
回答1:
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
回答2:
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 havedebugger;
string. So I debugging my nodeunit test with nodeinspector
来源:https://stackoverflow.com/questions/16652358/how-to-debug-nodeunit-using-node-inspector