如何使用节点检查器来debuggingnodeunit
我可以:
- 我可以使用nodeunittestingnode.js模块。
- 我可以使用节点检查器来debugging我的node.js express站点。
但是如何使用节点检查器来debuggingnodeunittesting?
我尝试了,但没有工作:
-
nodeunit --debug myNodeUnitModule_test.js
这不起作用。 - 我试图安装nodebug 。 并且像这样使用它:
nodebug /usr/local/bin/nodeunit myNodeunit_test.js
但是在ubuntu(No such file or directory
)和mac(env: node\r: No such file or directory
)
几乎工作 节点–debug / usr / local / bin / nodeunit ./routes/edit/bodyTelInfoArraysToObject_test.js
其中/usr/local/bin/nodeunit
是由which nodeunit
命令获取的path
得到输出: debugger listening on port 5858
并在那里执行testing。
但是我不能跳转到debugging:当我打开URL的localhost:8080
铬观看debugging:
- 第一次加载我看到空的文件列表
- 第二次加载:页面未find。
在我的nodeunittesting中,我写了debugger
来停止debugging。 但没有。
在你的testing中插入debugger;
命令
exports['Main test'] = function(test){ debugger; test.expect(1); test.ok(true, 'Must be ok'); test.done(); };
开始这一切
$ node --debug-brk `which nodeunit` test.js
现在在浏览器中按F8键,然后按F10键,在第一个debugger;
之后,你就在下一行了debugger;
命令在你的testing。
但是我更喜欢用node-supervisor启动所有的东西,当testing完成时自动重启testing,或者改变项目目录中的文件:
$ 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
解决scheme发现
-
在控制台中: node –debug-brk`哪个nodeunit` ./path/To/My/NodeUnitTests/nodeunit_test.coffee (注意:哪个nodeunit`在后面加引号)
-
在另一个控制台中:
node-inspector &
-
并在谷歌铬打开:http://0.0.0.0:8080/debug?port=5858在这里我看到nodeunit从一开始debugging。 在浏览器中点击继续执行几次,直到跳到nodeunittesting,在那里我有
debugger;
串。 所以我用nodeinspectordebugging我的nodeunittesting