我正在努力让 Visual Studio Code 调试器与 Jest 测试一起工作。
这是我的launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest All",
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"args": ["--runInBand"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"sourceMaps": true
}
]
}
这是我的带有几个断点的 Jest 测试:
当我点击绿色播放按钮使用调试器运行测试时,断点永远不会被击中。
任何帮助,将不胜感激
最佳答案
我个人使用这个配置
{
"name": "Launch e2e test",
"type": "node",
"request": "launch",
"env": {
"NODE_ENV": "test"
},
"args": [
"--colors",
"--config=${workspaceFolder}/jest-e2e.config.js",
"--runInBand",
"--coverage"
],
"runtimeArgs": [
"--nolazy"
],
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
},
"outputCapture": "std",
"internalConsoleOptions": "openOnSessionStart"
}
通过您的配置文件更改 jest-e2e.config.js。并删除或保留覆盖范围
就像劳拉·斯洛克姆说的那样,您肯定会遇到行号问题。就我而言,个人认为问题来自 Jest 配置,转换:
transform: {
"^.+\\.(t|j)s$": "ts-jest"
},
关于visual-studio-code - VSCode 调试器在 Jest 测试中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51009733/