I\'m trying to debug Jest unit tests using VS Code. I have the following config file settings
\"configurations\": [
{
\"name\": \"Debug Jest Te
@tmp dev, if you simply change runtimeArgs
to args
in your configuration, it would work:
"configurations": [
{
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"args": [
"${workspaceRoot}/node_modules/jest/bin/jest.js",
"--runInBand"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
runtimeArgs
is to runtimeExecutable as args
is to program. As you are launching Jest directly with node, in this case you should use args
passing arguments to node
. See the Nodejs debugging docs and this ticket for more details.
[2nd way] Specify the actual program to run:
"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"
}
]
[3rd way] If you would like to launch the debugger via npm (which is a runtimeExecutable), and your package.json looks like this:
{
"scripts": {
"test:unit:debug": "node --inspect-brk=9229 ./node_modules/jest/bin/jest.js --no-cache --runInBand"
},
...
}
You can launch the debugger using runtimeArgs
like this in VS Code:
{
"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
}
]
}