[FEATURE] a way to specify the nodejs executable
Is your feature request related to a problem? Please describe. i have a python project managed with pyprojectx and uv, which contains an npm package. the version of node/npm used in this project is managed as a pypi dependency using nodejs-wheel.
this means that node/npm is never installed globally, so by default jest fails with the following error:
/usr/bin/env: ‘node’: No such file or directory
to fix this, i can set jest.jestCommandLine to "./pw uv run npm run jest --" in settings.json, but that only works on linux. on windows, it fails with the following error:
'.' is not recognized as an internal or external command,
operable program or batch file.
Describe the solution you'd like
a way to specify a platform-specific value for jest.jestCommandLine, something like this:
{
"jest.jestCommandLine.linux": "./pw uv run npm run jest --",
"jest.jestCommandLine.windows": "pw uv run npm run jest --"
}
Describe alternatives you've considered
- jest could be updated to respect vscode's
terminal.integrated.env.*settings, which would allow me to add the correct node/npm binary to thePATHvariable - a way to customize the path to the node/npm binaries in vscode itself so that i don't need to configure this setting in jest at all, but i don't think such an option exists.
Additional context
- i specifically want to commit
.vscode/settings.jsonwhich is why the config must work on all platforms, since other contributors to my project may be using a different OS - vscode already has some settings like this, for example
terminal.integrated.env.windows,terminal.integrated.env.linux,terminal.integrated.env.osxwhich allows you to specify environment variables in the terminal for each OS - more info about why my project is set up this way
i found a workaround that kind of works:
{
"jest.jestCommandLine": "\"./pw\" uv run npm run jest --"
}
but it crashes on both windows and linux when running a test in debug mode.
windows:
> ${env:NODE_OPTIONS}=' --require c:/Users/user/AppData/Local/Programs/VSCodium/resources/app/extensions/ms-vscode.js-debug/src/bootloader.js --inspect-publish-uid=http'; ${env:VSCODE_INSPECTOR_OPTIONS}=':::{"inspectorIpc":"\\\\.\\pipe\\node-cdp.21284-4552a54d-86.sock","deferredMode":false,"waitForDebugger":"","execPath":"C:\\Program Files\\nodejs\\node.exe","onlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"C:\\Users\\user\\AppData\\Local\\Temp\\node-debug-callback-869cfb94dffdeaa4"}'; & 'C:\Program Files\nodejs\node.exe' '.\pw' 'uv' 'run' 'npm' 'run' 'jest' '--' '--runInBand' '--watchAll=false' '--testNamePattern' 'fourslash tests C:\\Users\\user\\basedpyright\\packages\\pyright-internal\\src\\tests\\fourslash\\rename\.args\.fourslash\.ts fourslash test rename\.args\.fourslash\.ts run$' '--runTestsByPath' 'C:\Users\user\basedpyright\packages\pyright-internal\src\tests\fourSlashRunner.test.ts'
cuser\x5cbasedpyright\x5cpackages\x5cpyright-internal\x5csrc\x5ctests\x5cfourSlashRunner.test.ts' ;386b7119-a2a6-4bfe-8e1a-b9f356c65e87Debugger attached.
Waiting for the debugger to disconnect...
C:\Users\user\basedpyright\pw:3
##################################################################################
^
SyntaxError: Invalid or unexpected token
at internalCompileFunction (node:internal/vm:77:18)
at wrapSafe (node:internal/modules/cjs/loader:1290:20)
at Module._compile (node:internal/modules/cjs/loader:1342:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1437:10)
at Module.load (node:internal/modules/cjs/loader:1212:32)
at Module._load (node:internal/modules/cjs/loader:1028:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12)
at node:internal/main/run_main_module:28:49
Node.js v21.6.1
linux:
(nothing shows up in the output log or terminal, just that popup)
actually i can't seem to get this to work on linux at all. i think instead i need an option to specify the node executable
Hi @DetachHead,
Thanks for the detailed feedback! There are a couple of things you raised here:
-
Platform-specific
jest.jestCommandLine- Yes, that’s a known limitation and has been requested before. I’ve added it as a feature proposal — hopefully we can support it in a future update.
-
Workaround using
jest.jestCommandLineworks for tests but not for debugging- That makes sense. While
jest.jestCommandLinecan run tests fine, it doesn't control how the debugger launches. It is not unusual for a complicated command-line to require a custom debug config. - The good news is that
launch.jsondoes support platform-specific configuration. You can define differentnodeor command-line setups like this:
- That makes sense. While
{
"type": "node",
"request": "launch",
"name": "vscode-jest-tests.v2",
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/index.js",
"runtimeExecutable": "/home/user/.nvm/versions/node/v18/bin/node",
"windows": {
"runtimeExecutable": "C:\\Program Files\\nodejs\\node18.exe"
},
"args": [
"jest",
"--runInBand",
"--watchAll=false",
"--testNamePattern",
"${jest.testNamePattern}",
"--runTestsByPath",
"${jest.testFile}"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
You’ll just need to set up a custom debug config in launch.json instead of relying on jest.jestCommandLine.
Let me know if you run into any issues setting it up!
thanks, i was eventually able to get it working using a debug config like that, a .bat script for windows and a bash script for linux:
.vscode/jest.bat:
@echo off
set PATH=%cd%/.venv/Scripts;%PATH%
npm run jest -- %*
.vscode/jest:
#!/bin/bash
PATH=$(pwd)/.venv/bin:$PATH
npm run jest -- "$@"
.vscode/settings.json:
{
// quotes needed so that it works in both cmd and bash
"jest.jestCommandLine": "\"./.vscode/jest\""
}
.vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"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}/packages/pyright-internal",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"runtimeExecutable": "${workspaceFolder}/.venv/bin/node",
"windows": {
"runtimeExecutable": "${workspaceFolder}/.venv/Scripts/node.exe",
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
}
}
]
}