【问题标题】:how to debug nodeunit using node-inspector如何使用 node-inspector 调试 nodeunit
【发布时间】:2013-05-15 04:17:14
【问题描述】:

我能做到:

  • 我可以使用 nodeunit 测试 node.js 模块。
  • 我可以使用 node inspector 调试我的 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) 上都不起作用

几乎可以工作 node --debug /usr/local/bin/nodeunit ./routes/edit/bodyTelInfoArraysToObject_test.js

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

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

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

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

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

【问题讨论】:

    标签: node.js nodeunit node-inspector


    【解决方案1】:

    在您的测试中插入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
    

    【讨论】:

      【解决方案2】:

      找到解决方案:

      • 在控制台中: node --debug-brk `which nodeunit` ./path/To/My/NodeUnitTests/nodeunit_test.coffee(注意:`which nodeunit` 在反引号中)

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

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

      【讨论】:

        猜你喜欢
        • 2011-09-04
        • 2013-07-15
        • 2014-06-13
        • 2017-07-03
        • 2012-09-30
        • 2012-09-11
        • 1970-01-01
        • 2015-05-11
        • 2015-05-04
        相关资源
        最近更新 更多