如何使用node-inspector调试nodeunit [英] how to debug nodeunit using node-inspector

查看:115
本文介绍了如何使用node-inspector调试nodeunit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以做到:

  • I can test node.js modules using nodeunit.
  • I can debug my node.js express site using node inspector.

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

But how to debug nodeunit test using node inspector?

我尝试了,但是没有用:

I tried, but not working:

  • 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)上工作
  • nodeunit --debug myNodeUnitModule_test.js It's not working.
  • I tried to install 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)

几乎可以使用 节点--debug/usr/local/bin/nodeunit ./routes/edit/bodyTelInfoArraysToObject_test.js

其中/usr/local/bin/nodeunit是命令which nodeunit

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

got output: debugger listening on port 5858 and test executed there.

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

But I can't jump in debuggin: when I open url localhost:8080 in chrome to watch debugging:

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

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

On my nodeunit test I wrote debugger to stop on debug there. But nothing.

推荐答案

在测试中插入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;命令之后,您就在下一行.

Now in browser press F8, then F10, and you are right on the next line after first 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:

$ 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

这篇关于如何使用node-inspector调试nodeunit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆