问题 如何使用node-inspector调试nodeunit


我可以:

但是如何使用节点检查器调试nodeunit测试?

我试过了,但没有工作:

  • 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

几乎是有效的 node --debug / usr / local / bin / nodeunit ./routes/edit/bodyTelInfoArraysToObject_test.js

哪里 /usr/local/bin/nodeunit 是命令采取的路径 which nodeunit

有输出: debugger listening on port 5858 并在那里执行测试。

但是我不能跳进debuggin:当我打开url时 localhost:8080 在chrome中观看调试:

  1. 第一次加载我看到空文件列表
  2. 第二次加载:找不到页面。

在我的nodeunit测试中,我写道 debugger 停止调试那里。 但没什么。


3891
2018-05-20 14:59


起源



答案:


在你的测试中插入 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; 测试中的命令。

但我更喜欢使用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

11
2018-05-22 12:20





解决方案:

  • 在控制台中: node --debug-brk`哪个nodeunit` ./path/To/My/NodeUnitTests/nodeunit_test.coffee (注意:`哪个nodeunit`在后面引用)

  • 在另一个控制台: node-inspector &

  • 并在谷歌Chrome开放: http://0.0.0.0:8080/debug?port=5858 在这里,我从一开始就看到nodeunit debuging。在浏览器中单击继续执行几次,直到跳转到nodeunit测试,我有 debugger; 串。所以我用nodeinspector调试我的nodeunit测试


3
2018-05-22 12:10