I've recently switched from Vim to VSCode, and I'm trying to set up VSCode debugging for jest tests run through docker.
The debugging works...sort of. If I want to run jest tests and have breakpoints activate, I need to:
- Insert the breakpoints
- Start running the relevant jest test(s) via the
vscode-jest-tests
launch.json task below - Quickly execute
Docker: Attach To Node
before the test suite hits breakpoints
Obviously not ideal - I'd love to ensure VSCode automatically attaches to the debugger upon running vscode-jest-tests
. In short: is there an easy way to attach the VSCode debugger when running Jest tests through Docker?
Here are my current launch.json and package.json files. Any help very appreciated:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Docker: Attach to Node",
"port": 9229,
"address": "localhost",
"localRoot": "${workspaceFolder}",
"remoteRoot": "/www",
"protocol": "inspector"
},
{
"type": "node",
"request": "launch",
"name": "vscode-jest-tests",
"runtimeExecutable": "npm",
"runtimeArgs": [ "run", "test:debug" ],
"address": "127.0.0.1",
"port": 9229,
"breakOnLoad": true,
"restart": true,
"timeout": 10000,
"localRoot": "${workspaceFolder}",
"remoteRoot": "/www",
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
package.json
#...
"scripts": {
"test:debug": "docker exec -it kiva_api node --nolazy --inspect-brk=0.0.0.0:9229 node_modules/.bin/jest --runInBand --config=test/jest-e2e.json"
}
#...
PS: If I run npm run test:debug
from the command line & have a chrome debugger window open, Chrome's debugger works just fine