使用 Visual Studio Code 的摩卡断点 [英] Mocha breakpoints using Visual Studio Code
问题描述
是否可以使用 Visual Studio Code 在 Mocha 测试中添加断点?
Is it possible to add breakpoints to Mocha tests using Visual Studio Code?
一般在调试代码时,需要配置launch.json,将program属性设置为Javascript文件来执行.不过,我不确定如何为 Mocha 执行此操作.
Normally when debugging code, one needs to configure the launch.json, setting the program attribute to the Javascript file to execute. I am not sure how to do this for Mocha though.
推荐答案
您知道吗,您只需进入启动配置,将光标放在其他配置之后或之间,然后按 ctrl-space 以获取自动生成的当前有效的 mocha 配置?
Did you know, that you just go into your launch config, put your cursor after or between your other configs and press ctrl-space to get a current, valid mocha config auto-generated?
这对我来说非常好.包括在断点处停止.(我也有一个以前的,现在已经过时的,由于各种与设置相关的原因而不再使用.)
Which works perfectly fine for me. Including stopping at breakpoints. ( I also had a prior, now outdated one, that did no longer for various setting-related reasons. )
从 VSCode 1.21.1(2018 年 3 月)开始,结果如下:
As of VSCode 1.21.1 (March 2018) this yields:
{
"version": "0.2.0",
"configurations": [
{
"name": "Mocha (Test single file)",
"type": "node",
"request": "launch",
"runtimeArgs": [
"${workspaceRoot}/node_modules/.bin/mocha",
"--inspect-brk",
"${relativeFile}",
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"port": 9229
}
}
附注:debug-brk
已弃用(至少适用于 Node >= 版本 8 的任何人).
On a side-note: debug-brk
is deprectated (for anyone with Node >= Version 8 at least).
这篇关于使用 Visual Studio Code 的摩卡断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!