如何使用node-inspector调试nodeunit

Max*_*mov 11 node.js nodeunit node-inspector

我可以:

  • 我可以使用nodeunit测试node.js模块.
  • 我可以使用节点检查器调试我的node.js express站点.

但是如何使用节点检查器调试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)上工作

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

其中/usr/local/bin/nodeunit是命令采用的路径which nodeunit

获得输出: debugger listening on port 5858 并在那里执行测试.

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

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

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

glu*_*kki 11

在您的测试中插入debugger;命令

exports['Main test'] = function(test){
    debugger;

    test.expect(1);
    test.ok(true, 'Must be ok');
    test.done();
};
Run Code Online (Sandbox Code Playgroud)

并开始这一切

$ node --debug-brk `which nodeunit` test.js
Run Code Online (Sandbox Code Playgroud)

现在在浏览器中按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
Run Code Online (Sandbox Code Playgroud)