调试摩卡测试的最小阻力路径是什么? [英] what's the least resistance path to debugging mocha tests?

查看:271
本文介绍了调试摩卡测试的最小阻力路径是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Edit Nov 2016:Node现在有一个内置的调试器,您可以从 - inspect 开始。此答案解释了此问题: http://stackoverflow.com/a/39901169/30946

Edit Nov 2016: Node now has a built in debugger that you can start with --inspect. This answer explains it: http://stackoverflow.com/a/39901169/30946.

我在coffeescript中建立一个摩卡测试。在测试的顶部,我有:

I'm building a mocha test in coffeescript. Right at the top of the test I have:

require "../assets/js/theObject.coffee"
debugger
ss = new TheObject()

因为 theObject.coffee 中的对象未加载。我使用节点检查器和它的工作,排序。

I'd like to stop on that debugger line because the object in theObject.coffee isn't being loaded. I'm using node-inspector and it works, sorta.

我的过程是:


  1. start node-inspector

  2. 在命令行中使用 mocha --compilers coffee:coffee-script运行测试./test/theObjectTests.coffee --ui bdd -d --debug-brk

  3. 转到节点检查器页面,如果已打开则刷新

  4. 等待文件 theObject.coffee 以加载,然后将断点放在正确的行上

  1. start node-inspector
  2. run the test at the command line with mocha --compilers coffee:coffee-script ./test/theObjectTests.coffee --ui bdd -d --debug-brk
  3. go to the node-inspector page, refresh it if it is already open
  4. wait for the file theObject.coffee to be loaded, then put a breakpoint on the correct line

必须是更容易的方式。看起来我应该能够有一个调试器运行,只是停止在调试器行,但我不能找到。

There must be an easier way. It seems like I should be able to have a debugger running and just have it stop on that debugger line, but I'm not able to find that.

我有WebStorm,它有一个调试器(本文讨论设置它运行mocha测试,但它没有帮助我),但当我开始它,它失败。在WebStorm调试窗口中运行的命令是:

I have WebStorm, which has a debugger (this article discusses setting it up to run mocha tests, but it didn't help me), but when I start it, it fails. The command that's running in the WebStorm debug window is:

"C:\Program Files\nodejs\node.exe" --debug-brk=64232 C:\Users\jcollum\AppData\Roaming\npm\_mocha

C:\Users\jcollum\AppData\Roaming\npm\_mocha:2
basedir=`dirname "$0"`

I怀疑可能是Windows特定问题。

I suspect that might be a windows specific issue.

Env:Windows 7,Webstorm,节点0.8.16,mocha 1.7.4,git-bash

Env: Windows 7, Webstorm, node 0.8.16, mocha 1.7.4, git-bash

问题:如果你从零开始与摩卡,什么是最容易的方法来获得一个调试器将停止在调试器线很容易? Easy是这里的关键。

The question: if you're starting from scratch with Mocha, what's the easiest way to get a debugger going that will stop on a debugger line easily? Easy is the keyword here.

编辑:自从提出这个问题后,我停止使用Windows并在Ubuntu中工作。我的摩卡调试过程(我不经常使用)是一样的。

since asking this I've stopped using Windows and am working in Ubuntu. My mocha debugging process (which I use infrequently) is the same.

推荐答案

多年后编辑:节点6+中的最短路径可能涉及 - inspect 标志。如果我回去摩卡测试,我会更新这个。

Edit, years later: the shortest path in Node 6+ probably involves the --inspect flag from the command line. I'll update this if I go back to mocha tests

很多周后,没有答案。这是我发现的最快的路径。

Many weeks later, no answers. Here's the quickest path that I found.


  1. 写入mocha测试

  2. 安装 node-inspector

  3. 开始节点检查员 - 现在正在侦听5858

  4. 使用 - debug-brk

  5. 启动mocha测试。此时,mocha测试暂停在第一行

  6. 打开Web浏览器并转到localhost:5858

  7. (可选:在测试文件的顶部添加调试器行,该文件)

  8. 点击F10以获取代码

  9. 节点检查器将在任何具有调试器就可以了。有时它不会将代码文件的窗口移动到正确的位置,所以你必须按F10,让它步到下一行,并显示它在文件中的位置。

  1. write mocha tests
  2. install node-inspector
  3. start node-inspector -- it will now be listening on 5858
  4. start the mocha test with --debug-brk
  5. at this point the mocha test is paused on the first line
  6. open a web browser and go to localhost:5858
  7. (optional: add a debugger line at the top of your test file, set breakpoints after it stops in that file)
  8. hit F10 to get the code to go
  9. node-inspector will stop on any line that has debugger on it. Occasionally it won't move the code file's window to the right place, so you'll have to hit F10 to get it to step to the next line and show where it's at in the file.

命令行:

& mocha --compilers coffee:coffee-script / register ./test/appTests.coffee --ui bdd -d -gshould X then Y--debug-brk

这篇关于调试摩卡测试的最小阻力路径是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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