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

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

问题描述

2016 年 11 月Node 现在有一个内置调试器,您可以从 --inspect 开始.这个答案解释了它:https://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: https://stackoverflow.com/a/39901169/30946.

我正在使用 coffeescript 构建一个 mocha 测试.就在我的测试顶部:

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. 启动节点检查器
  2. 在命令行使用 mocha --compilers coffee:coffee-script ./test/theObjectTests.coffee --ui bdd -d --debug-brk
  3. 运行测试
  4. 转到节点检查器页面,如果它已经打开,请刷新它
  5. 等待文件 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,它有一个调试器 (this article讨论设置它来运行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
odejs
ode.exe" --debug-brk=64232 C:UsersjcollumAppDataRoaming
pm\_mocha

C:UsersjcollumAppDataRoaming
pm\_mocha:2
basedir=`dirname "$0"`

我怀疑这可能是特定于 Windows 的问题.

I suspect that might be a windows specific issue.

环境: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

问题:如果您是从头开始使用 Mocha,让调试器运行并轻松停止在调试器行上的最简单方法是什么?简单是这里的关键词.

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 中工作.我的 mocha 调试过程(我不经常使用)是一样的.

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

推荐答案

几年后编辑:Node 6+ 中的最短路径是:mocha --debug-brk --inspect./test.js 加上 Node Inspector Manager 插件.

Edit, years later: the shortest path in Node 6+ is: mocha --debug-brk --inspect ./test.js coupled with the Node Inspector Manager plugin.

许多周后,没有答案.这是我找到的最快路径.

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

  1. 编写 mocha 测试
  2. 安装节点检查器
  3. 启动 node-inspector -- 现在它将监听 5858
  4. 使用 --debug-brk
  5. 开始 mocha 测试
  6. 此时 mocha 测试在第一行暂停
  7. 打开网络浏览器并转到 localhost:5858
  8. (可选:在测试文件的顶部添加调试器行,在该文件中停止后设置断点)
  9. 按 F10 获取代码
  10. node-inspector 将停在任何有 debugger 的行上.有时它不会将代码文件的窗口移动到正确的位置,因此您必须按 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 -g "should X then Y" --debug-brk

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

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