我有一个Jest测试套件,我想使用VS Code交互式调试器进行调试。对于正常的NodeJS程序("program": "foo.js"
中的launch.json
)来说,这很好用。但是测试套件(foo.test.js
)并不是一个自包含的程序,它必须从Jest运行。
有没有办法做到这一点?
答案 0 :(得分:2)
vscode-recipies描述了如何设置VS Code来调试标准的Jest测试。
launch.json看起来像这样:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest All",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["--runInBand"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
}
},
{
"type": "node",
"request": "launch",
"name": "Jest Current File",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["${relativeFile}"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
}
}
]
}
如果您的应用程序是使用create-react-app引导的React应用程序,则配置会有所不同,因为Jest不会直接启动,并且在create-react-app文档的this section中进行了描述。>