Skip to content
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] nvm not used and version not applied #1155

Open
obrejla opened this issue Jun 13, 2024 · 2 comments
Open

[BUG] nvm not used and version not applied #1155

obrejla opened this issue Jun 13, 2024 · 2 comments

Comments

@obrejla
Copy link

obrejla commented Jun 13, 2024

Describe the bug
When my jest config and srcs are under directory with .nvmrc, then the proper version of the node is not used for running jest tests. It used just the default.

To Reproduce
Have a project which uses nvm for managing node versions, have the "default" different from what is required by the test runner...try to run tests in vscode via your extension. The default node version is used, not the one specified by .nvmrc in the project directory.

Expected behavior
Test runner embraces nvmrc and node version specified in it.

Environment (please complete the following information):

  • Operating system: MacOS 14.3.1

Prerequisite

  • are you able to run jest from the command line? yes

Additional context

  • it works properly in IntelliJ
@connectdotz
Copy link
Collaborator

This extension will start a non-login/non-interactive shell to run the jestCommandLine, therefore, the location of your nvm setting matters. For example, in zsh, if you put the nvm config/loading logic in .zshrc, it will only work for the interactive shells (the terminals). You might need to consider moving the nvm logic to .zshenv or changing the jest.env to login-shell, for example.

@forivall
Copy link

forivall commented Oct 4, 2024

I have figured out some workarounds: I use direnv to load nvm, though these solutions may work for other node version management tools.

For running tests without debugging, the following setup works:

  "jest.shell": {
    "path": "direnv",
    "args": ["exec", ".", "zsh"]
  },

I think the following will work for pure nvm, though it should be in your workspace or folder settings as it'll only work if an .nvmrc file is available:

  "jest.shell": {
    "path": "$HOME/.nvm/nvm-exec",
    "args": ["zsh"]
  }

You'll need to replace $HOME with your home directory.

For running tests in debugging, I added the following to my .zshrc (or in something source'd by your .zshrc, because for some reason, it insists on using the system node:

if [[ $TERM_PROGRAM == vscode ]]; then
  function zleenvnode() {
    emulate -L zsh
    setopt extendedglob

    local MATCH
    if [[ $LBUFFER = ' /usr/bin/env'* || $LBUFFER = ' cd '*'; /usr/bin/env'* ]]; then
      local NVM_NODE="$(whence node)"
      LBUFFER="${LBUFFER//\/opt\/homebrew\/bin\/node/$NVM_NODE}"
      return
    fi
  }
  autoload -U add-zle-hook-widget
  add-zle-hook-widget -Uz line-finish zleenvnode
fi

This uses zsh features to modify the command just before it's executed in the integrated terminal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants