如果包含端口和“--debug-brk”参数,您应该可以调试摩卡单元测试。我在launch.json文件中有以下设置。我还包括“ - 递归”参数,所以摩卡会在子文件夹中运行所有测试。使用这个配置文件,我只需将我的VS Code调试器设置为使用“调试摩卡测试”配置,我就可以在我的任何测试文件中找到断点。
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}/server.js",
"cwd": "${workspaceRoot}"
},
{
"type": "node",
"request": "attach",
"name": "Attach to Process",
"port": 5858
},
{
"type": "node",
"request": "launch",
"name": "Debug Mocha Test",
"port": 5858,
"runtimeArgs": ["${workspaceRoot}/node_modules/mocha/bin/mocha"],
"cwd": "${workspaceRoot}",
"args": ["--recursive", "--debug-brk"]
}
]
}
可以验证端口摩卡将通过运行mocha --debug-brk
哦用于调试,我应该检查我自己。我虽然/ usr/bin/mocha会很好,并没有考虑过三次。 – Nathan