Closed kruncher closed 3 months ago
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 .vscode/launch.json
as mentioned in these docs:
{
"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 name
is important here, if it does not start with vscode-jest-tests.v2
the default config will be generated and used implicitly.
@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.
Please see here:
@connectdotz here is a paste of my debug config (some private info has been masked)
{
"type": "node",
"name": "vscode-jest-tests.v2.{reponame}",
"request": "launch",
"args": [
"test",
"--",
"--runInBand",
"--watchAll=false",
"--testNamePattern",
"${jest.testNamePattern}",
"--runTestsByPath",
"${jest.testFile}"
],
"cwd": "c:\\code\\{reponame}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"runtimeExecutable": "npm"
}
jest is generating a command line seen here: (again private info masked)
/usr/bin/env 'NODE_OPTIONS= --require "c:/Users/*****/AppData/Local/Programs/Microsoft VS Code/resources/app/extensions/ms-vscode.js-debug/src/bootloader.js" --inspect-publish-uid=http' 'VSCODE_INSPECTOR_OPTIONS=:::{"inspectorIpc":"\\\\.\\pipe\\node-cdp.34560-666e75fc-19.sock","deferredMode":false,"waitForDebugger":"","execPath":"C:\\Program Files\\nodejs\\node.exe","onlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"C:\\Users\\*****\\AppData\\Local\\Temp\\node-debug-callback-72e6e64a92552add"}' C:\\Program\ Files\\nodejs\\npm.cmd test -- --runInBand --watchAll=false --testNamePattern VerbCompressPdfConfig\ tests\ expects\ the\ right\ bootstrap\ properties\ to\ be\ loaded\$ --runTestsByPath C:\\code\\*****\\src\\bootstrapConfig\\CompressPDF\\VerbCompressPdfConfig.spec.js
the correct command line would be:
/usr/bin/env 'NODE_OPTIONS= --require "c:/Users/*****/AppData/Local/Programs/Microsoft VS Code/resources/app/extensions/ms-vscode.js-debug/src/bootloader.js" --inspect-publish-uid=http' 'VSCODE_INSPECTOR_OPTIONS=:::{"inspectorIpc":"\\\\.\\pipe\\node-cdp.34560-666e75fc-19.sock","deferredMode":false,"waitForDebugger":"","execPath":"C:\\Program Files\\nodejs\\node.exe","onlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"C:\\Users\\*****\\AppData\\Local\\Temp\\node-debug-callback-72e6e64a92552add"}' "C:\\Program\ Files\\nodejs\\npm.cmd" test -- --runInBand --watchAll=false --testNamePattern VerbCompressPdfConfig\ tests\ expects\ the\ right\ bootstrap\ properties\ to\ be\ loaded\$ --runTestsByPath C:\\code\\*****\\src\\bootstrapConfig\\CompressPDF\\VerbCompressPdfConfig.spec.js
Please notice the additional quotes around the "C:\\Program\ Files\\nodejs\\npm.cmd"
also, i would ask, how can we replace the usage of "{npm cmd line}" test
with something more generic such as npx jest
? Not all projects have a "test" script that is suitable for this purpose. In our case, for many (maybe wrong but beyond my power to change) reasons, our "test" script also runs linting and a number of other unnecessary (in the context of "testing") steps, which make it not suitable for use as the debug test runner.
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:
"windows"
config as @olifer mentioned.npm test
. If you want to run npx jest
, you can change the config accordingly.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. This is my launch.json config:
{
"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