简体   繁体   English

如何使用node-inspector调试nodeunit

[英]how to debug nodeunit using node-inspector

I can do: 我可以:

  • I can test node.js modules using nodeunit . 我可以使用nodeunit测试node.js模块。
  • I can debug my node.js express site using node inspector . 我可以使用节点检查器调试我的node.js express站点。

But how to debug nodeunit test using node inspector? 但是如何使用节点检查器调试nodeunit测试?

I tried, but not working: 我试过了,但没有工作:

  • nodeunit --debug myNodeUnitModule_test.js It's not working. nodeunit --debug myNodeUnitModule_test.js它没有用。
  • I tried to install nodebug . 我试着安装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 ) 并且像这样使用它: nodebug /usr/local/bin/nodeunit myNodeunit_test.js但是它既不在ubuntu( No such file or directory )也不在mac上工作( env: node\\r: No such file or directory

Almost works node --debug /usr/local/bin/nodeunit ./routes/edit/bodyTelInfoArraysToObject_test.js 几乎工作 节点--debug / usr / local / bin / nodeunit ./routes/edit/bodyTelInfoArraysToObject_test.js

where /usr/local/bin/nodeunit is path taken by command which nodeunit 其中/usr/local/bin/nodeunit是命令采用which nodeunit路径

got output: debugger listening on port 5858 and test executed there. 得到输出: debugger listening on port 5858并在那里执行测试。

But I can't jump in debuggin: when I open url localhost:8080 in chrome to watch debugging: 但是我不能跳进debuggin:当我在chrome中打开url localhost:8080来监视调试时:

  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. 在我的nodeunit测试中,我编写了debugger来停止调试。 But nothing. 但没什么。

In your tests insert debugger; 在你的测试中插入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; 现在在浏览器中按F8,然后按F10,你就在第一个debugger;后的下一行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: 但我更喜欢使用node-supervisor启动所有内容,在测试完成或项目目录中的文件发生更改时自动重启测试:

$ 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) 在console: node --debug-brk`哪个nodeunit` ./path/To/My/NodeUnitTests/nodeunit_test.coffee (注意:`哪个nodeunit`在后引号中)

  • in another console: node-inspector & 在另一个控制台中: node-inspector &

  • And in google chrome open: http://0.0.0.0:8080/debug?port=5858 Here I see nodeunit debuging from the start. 而在谷歌浏览器打开: http://0.0.0.0:8080/debug?port=5858在这里,我看到nodeunit从一开始调试。 Click continue execution several times in browser until jump to nodeunit test, where I have debugger; 在浏览器中单击几次继续执行,直到跳转到nodeunit test,我有debugger; string. 串。 So I debugging my nodeunit test with nodeinspector 所以我用nodeinspector调试我的nodeunit测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM