vscode-jest
vscode-jest copied to clipboard
Feature - Run jest with specified node version from .nvmrc file
Since the plugins starts without allowing the user to specify what version of node should be used, and use the default selected version in its own process, it is not yet possible to select what version of node should be used.
In my case, my default nvm node version is 4.x. But my project has a .nvmrc with 6.9.1
in it. But Jest uses the default one. (which makes the whole extension unusable since it crashed instantly)
Would it be possible to either specify what path of node we want Jest to use, or, more simply, run a nvm use
before the plugin starts if there is a .nvmrc
file in the root folder?
This seems reasonable to me, it'll have to go in jest-editor-support ( which has just had some changes related to this https://github.com/facebook/jest/pull/2817 )
Definitely needed, current node version management seems difficult.
Also please update README that to change node version for tests one has to do
nvm alias default $REQUIRED_NODE_VERSION
PRs welcome 👍
I know this issue is pretty old, is there a proposed solution or suggested workaround on how to get the watch test use the right node version using nvm?
For what it's worth, when using the debug
launch lens, it uses the node version specified in in launch.json
, so that works. But the watched test seems to not be using launch..?
For what it's worth, when using the
debug
launch lens, it uses the node version specified in inlaunch.json
, so that works. But the watched test seems to not be using launch..?
Same. @orta how do I get jest in watch mode to use the node version specified in launch.json
?
I am also looking for a solution to use this plugin with nvm...
same here, watch not working
During debugging, this extension uses vscode's debug infrastructure that used launch.json; during the regular test run/watch it spawns a node process instead. It would default to the node version from your default shell... I use nvm and it works fine. Do you guys actually want to use a different node version than your default nvm?
During debugging, this extension uses vscode's debug infrastructure that used launch.json; during the regular test run/watch it spawns a node process instead. It would default to the node version from your default shell... I use nvm and it works fine. Do you guys actually want to use a different node version than your default nvm?
Yes, I'd want to use the version specified in the .nvmrc
file, not the shell default.
I got it working using a startup script:
- Create a
node.sh
wrapper script to set up the Node version from.nvmrc
. (Update shebang andsource
line to match your shell.)#!/bin/zsh source ~/.zshrc nvm exec $*
- Update
.vscode/settings.json
to use the wrapper. (Updatejest
command to match how you normally run it.)
{
"jest.jestCommandLine": "./node.sh npx jest"
}
1. Create a `node.sh` wrapper script to set up the Node version from `.nvmrc`. (Update shebang and `source` line to match your shell.) ```shell #!/bin/zsh source ~/.zshrc nvm exec $* ```
Instead of creating your own script, you can use ~/.nvm/nvm-exec
for this:
{
"jest.jestCommandLine": "~/.nvm/nvm-exec npx test"
}
If you use zsh
plus nvm
auto version switch, you can simply:
"jest.jestCommandLine": "source ~/.zshrc && nvm exec $* && yarn test"
Of course switching to npm run test
, npx test
, as you wish, instead of yarn test
.
Also not sure if this is needed but it's possible:
"jest.shell": "/bin/zsh",