@tmp 开发人员,如果您只是在配置中将 runtimeArgs 更改为 args,它将起作用:
"configurations": [
{
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"args": [
"${workspaceRoot}/node_modules/jest/bin/jest.js",
"--runInBand"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
runtimeArgs 是 runtimeExecutable 就像 args 是编程。当您直接使用节点启动 Jest 时,在这种情况下,您应该使用 args 将参数传递给 node。有关详细信息,请参阅 Nodejs debugging docs 和 this ticket。
[2nd way]指定实际运行的程序:
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest Test",
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"args": ["--runInBand", "--config=${workspaceFolder}/jest.config.js"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
[第三种方式]如果您想通过 npm(它是一个 runtimeExecutable)启动调试器,并且您的 package.json 看起来像这样:
{
"scripts": {
"test:unit:debug": "node --inspect-brk=9229 ./node_modules/jest/bin/jest.js --no-cache --runInBand"
},
...
}
您可以在 VS Code 中像这样使用runtimeArgs 启动调试器:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch via npm",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "npm",
"runtimeArgs": ["run-script", "test:unit:debug"],
"port": 9229
}
]
}