使用Visual Studio Code的Mocha断点 [英] Mocha breakpoints using Visual Studio Code
问题描述
是否可以使用Visual Studio Code在Mocha测试中添加断点?
Is it possible to add breakpoints to ones Mocha tests using Visual Studio Code?
通常,在调试代码时,需要配置launch.json,将program属性设置为要执行的javascript文件.我不确定如何为摩卡咖啡做到这一点.
Normally when debugging code one need 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 空间以获得自动生成的当前有效的摩卡配置?
哪个对我来说很好.包括在断点处停止. (我还有一个以前的,现在已经过时的,由于各种与设置有关的原因,它不再存在.)
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的Mocha断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!