You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
are you able to run jest test from the command line? yes
how do you run your tests from the command line? pnpm run test
Steps to Reproduce
Set jestCommandLine to pnpm run test -- and use the debug test workflow.
Expected Behavior
The package script will be correctly delegated to for jest binary invocation.
Actual Behavior
The invocation will show node invoking the specified string expecting it to be a path to a module:
[...] /usr/local/bin/node ./pnpm run test
causing "Cannot find module" error. This works with npm run test because usage of a "magic string" (npm) changes the debug invocation to refer to the package manager instead of the local node binary.
will-wow, leandroaguiar-lr, w121211, mjames-c, tjhorner and 1 more
I have faced the weirdest issue that might be related. I was using a Windows machine and in a Next.js project of mine I have Jest 29.7 configured manually, exactly as depicted in this article. If there was any key difference from a typical Next.js project, it is that I was using pnpm. I took care to set jestCommandLine to pnpm run test -- (package.json/scripts/test was set to "jest" of course) but if I did that, the command line built upon running from the extension is like
jest "--" "--testLocationInResults" "--json" "--useStderr" ...
and then Jest wouldnt find any of my tests and exit with error (testRegex would get 0 matches). I found out that the "--" in jest invocation was causing all this, what I did not expect was that setting jestCommandLine to pnpm test -- would fix this issue. It makes no sense, but then maybe this was the cause.
- parse `jest.jestCommandLine` into command and arguments. Resolve relative command path based on `jest.rootPath` if defined otherwise uses vscode variable `"${workspaceFolder}"`.
- obtain a debug template from `DebugConfigurationProvider`
- merge the jest command and arguments with the template.
- if the command is `npm` or `yarn` it updates `runtimeExecutable` property; otherwise updates `program`
- the arguments will be added to the `args` property, plus jest debug specific flags such as `--runInBand`.
- update `cwd` property with either `jest.rootPath` if defined, otherwise the vscode variable `"${workspaceFolder}"`
According to setup-wizard "How is debug config generated" section, jest plugin updates runtimeExecutable property if the command is npm or yarn , otherwise updates program.
pnpm is not one of it , so it updates program to "program": "[project root]/node_modules/.bin/jest".
However , the core problem is that pnpm creates the Jest binary file (node_modules/.bin/jest) as a shell script rather than a Node.js script, which cause issue like #868 . and this is also why #1046 would not work.
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1033:15)
at Module._compile (node:internal/modules/cjs/loader:1069:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Module._load (node:internal/modules/cjs/loader:827:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
User's own jestCommandLine might also not be node js as well, so the program field is not the answer. (scripts in package.json could also be shell scripts)
The alternatives' are
make runtimeExecutable in package.jsonsh (But this probably would not work on windows, we need find out how to work on window)
make runtimeExecutable pnpm
Pnpm do have settings like prefer-symlinked-executables, but it is not default and might not be used on windows.
so it would be nice to make this plugin support pnpm and other future package managers. @connectdotz
Activity
connectdotz commentedon Dec 23, 2022
That's true, want to work on a PR? should be pretty straightforward:
vscode-jest/src/DebugConfigurationProvider.ts
Line 157 in 3deb1af
ermik commentedon Dec 26, 2022
Thanks for asking, I might. Will post here if I pick this up. 💟
orpheus6678 commentedon Feb 7, 2025
I have faced the weirdest issue that might be related. I was using a Windows machine and in a Next.js project of mine I have Jest 29.7 configured manually, exactly as depicted in this article. If there was any key difference from a typical Next.js project, it is that I was using pnpm. I took care to set
jestCommandLine
topnpm run test --
(package.json/scripts/test was set to "jest" of course) but if I did that, the command line built upon running from the extension is likejest "--" "--testLocationInResults" "--json" "--useStderr" ...
and then Jest wouldnt find any of my tests and exit with error (
testRegex
would get 0 matches). I found out that the "--" in jest invocation was causing all this, what I did not expect was that settingjestCommandLine
topnpm test --
would fix this issue. It makes no sense, but then maybe this was the cause.icy0307 commentedon May 19, 2025
vscode-jest/setup-wizard.md
Lines 127 to 133 in c93ec7a
According to setup-wizard "How is debug config generated" section, jest plugin updates
runtimeExecutable
property if the command isnpm
oryarn
, otherwise updatesprogram
.pnpm is not one of it , so it updates
program
to"program": "[project root]/node_modules/.bin/jest"
.However , the core problem is that pnpm creates the Jest binary file (node_modules/.bin/jest) as a shell script rather than a Node.js script, which cause issue like #868 . and this is also why #1046 would not work.
User's own jestCommandLine might also not be node js as well, so the program field is not the answer. (scripts in package.json could also be shell scripts)
The alternatives' are
runtimeExecutable
inpackage.json
sh
(But this probably would not work on windows, we need find out how to work on window)runtimeExecutable
pnpmPnpm do have settings like prefer-symlinked-executables, but it is not default and might not be used on windows.
so it would be nice to make this plugin support pnpm and other future package managers.
@connectdotz