问题
I have a Jest test suite that I would like to debug using the VS Code interactive debugger. That works fine for normal NodeJS programs ("program": "foo.js"
in launch.json
). But the test suite (foo.test.js
) isn't a self-contained program, it has to be run from Jest.
Is there a way to achieve this?
The particular code is here: https://gitlab.com/stevage/guess-projection
回答1:
Debugging standard Jest tests
This doc in Microsoft's vscode-recipies GitHub repo describes how to set up VS Code for debugging standard Jest tests.
The launch.json looks like this:
{
"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",
}
}
]
}
Debugging create-react-app Jest tests
If your application is a React app bootstrapped with create-react-app then the configuration is a little different since Jest is not launched directly and is described in this section of the create-react-app docs.
来源:https://stackoverflow.com/questions/53508251/how-to-interactively-debug-a-nodejs-test-suite-in-vs-code