-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Fails to debug tests on Windows due to issue with paths #1152
Comments
hi the command line didn't seem to be complete. Please repaste the full command line; and your debug config for jest if you have a customized one. |
I've encountered a similar issue on Windows due to the generated configuration by default. Try to define your test config in {
"type": "node",
"name": "vscode-jest-tests.v2",
"request": "launch",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"--runInBand",
"--watchAll=false",
"--testNamePattern",
"${jest.testNamePattern}",
"--runTestsByPath",
"${jest.testFile}"
],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
}
} Notice that the |
@olifer this does not solve the problem. I have also followed these steps, but they were not necessary in the first place as the command line is being generated fine without customizing the config. the issue is that the generated command line is missing quotes around the "npm.cmd" path. |
@connectdotz
jest is generating a command line seen here: (again private info masked)
the correct command line would be:
Please notice the additional quotes around the |
also, i would ask, how can we replace the usage of It is not scalable to ask developers to locally change their test script to be pure test scripts just to use this tool. This tool should be configurable to run tests however the project requires. The previous iteration of this project "Jest Test Explorer UI" had no such problems with our projects. I will have to continue to use it until these issues are fixed. |
@connectdotz Just following up on this. Is there further information that can help us find a resolution? |
@davidcoleman007 I have a few suggestions:
For example, you can try something like this: {
"type": "node",
"name": "vscode-jest-tests.v2.{reponame}",
"request": "launch",
"args": [
"jest", // <= changed
"--",
"--runInBand",
"--watchAll=false",
"--testNamePattern",
"${jest.testNamePattern}",
"--runTestsByPath",
"${jest.testFile}"
],
"cwd": "c:\\code\\{reponame}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"windows": {
"runtimeExecutable": "npx" // <= changed
}
} As you can see, you have full control over what command the debugger should launch with. The extension only substitutes the variables in the config, such as ${jest.testNamePattern}; it doesn't impose any additional constraints. Feel free to experiment (like adding quotes or the full path of the program if VSCode didn't spawn the right command line), and let us know if you have any additional questions. |
I've resolved simply by calling directly jest from node modules instead of passing through npm. {
"type": "node",
"name": "vscode-jest-tests.v2.{PROJECT_NAME}", // Adapt this
"request": "launch",
"args": [
// Removed first two params from the command
"--runInBand",
"--watchAll=false",
"--testNamePattern",
"${jest.testNamePattern}",
"--runTestsByPath",
"${jest.testFile}"
],
"cwd": "${workspaceRoot}",
"console": "integratedTerminal",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/jest", // Changed this
} |
Great! Yes, the debug configuration in VSCode is quite flexible—kudos to the team for that. I encourage everyone to experiment with it; you should be able to find a solution that works for your project. Since no further action is required from the extension, I’ll go ahead and close this issue. |
Describe the bug
I am seeing the following error when attempting to debug a unit test:
Some useful points:
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Unit test should run and should break at breakpoint.
Environment (please complete the following information):
node -v
: 22.2.0npm -v
oryarn --version
: 10.7.0Prerequisite
The text was updated successfully, but these errors were encountered: