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

shell doesn't inherit env variables in vscode 1.64.0 #833

Closed
Chooks22 opened this issue Feb 4, 2022 · 4 comments · Fixed by #874
Closed

shell doesn't inherit env variables in vscode 1.64.0 #833

Chooks22 opened this issue Feb 4, 2022 · 4 comments · Fixed by #874

Comments

@Chooks22
Copy link

Chooks22 commented Feb 4, 2022

Environment

  1. vscode-jest version: 4.2.1
  2. node -v: 16.13.2
  3. npm -v or yarn --version: 8.1.2
  4. npm ls jest or npm ls react-scripts (if you haven’t ejected): 27.4.7
  5. your vscode-jest settings if customized:
    • "jest.shell": "zsh"
    • anything else that you think might be relevant?
      • pnpm 6.29.1
      • multi-root repo "jest.jestCommandLine": "pnpm t --"
  6. Operating system: Arch Linux

Prerequisite

  • are you able to run jest test from the command line? yes
  • how do you run your tests from the command line? (for example: npm run test or node_modules/.bin/jest) pnpm t

Steps to Reproduce

Upgrade to vscode 1.64.0, making sure that the path to your package manager is set by a profile like .zshrc

Relevant Debug Info

Replace jestCommandLine with echo $PATH &&.

It should print out the system default PATH variable, without inheriting from the values set by the profile files.

Running echo $PATH in the integrated terminal works fine.
Running vscode 1.63.2 works fine.

Related vscode config: terminal.integrated.inheritEnv

Expected Behavior

Runs as normal.

Actual Behavior

zsh:1: command not found: pnpm

The fastest (and the most fun) way to resolve the issue is to submit a pull-request yourself. If you are interested, feel free to check out the contribution guide, we look forward to seeing your PR...

@Chooks22 Chooks22 changed the title shell doesn't inherit env variables shell doesn't inherit env variables in vscode 1.64.0 Feb 4, 2022
@connectdotz
Copy link
Collaborator

hi @Choooks22 a few questions:

  • Where is the path set (rc or profile)?
  • what is the output of "echo $PATH" via jest.jestCommandLine?
  • what is the value of your terminal.integrated.inheritEnv?

@Chooks22
Copy link
Author

Chooks22 commented Feb 5, 2022

Where is the path set (rc or profile)?

it's set in ~/.zshrc using the nvm oh-my-zsh plugin

what is the output of "echo $PATH" via jest.jestCommandLine?

/home/chooks/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/opt/android-sdk/platform-tools:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl --testLocationInResults --json --useStderr --outputFile /tmp/jest_runner____framework.json --watch --no-coverage --reporters default --reporters /home/chooks/.vscode/extensions/orta.vscode-jest-4.2.1/out/reporter.js --colors

what is the value of your terminal.integrated.inheritEnv?

"terminal.integrated.inheritEnv": true

@connectdotz
Copy link
Collaborator

@Choooks22 please see this comment for a detailed explanation of how jest is executed in the shell env. Essentially we use a non-login/non-interactive shell, so it inherits vscode process env and does not automatically source ~/.zshrc again.

This is different from vscode terminal, which creates a login shell, so it always sources the setup files (rc, profile etc). The terminal setting "terminal.integrated.inheritEnv" does not impact jest process in any way.

I am not sure what vscode 1.64.0 has changed to impact this behavior, maybe it failed to fully initialize the process env during the start-up? Perhaps try to launch vscode from a Linux terminal (which should have the env initialized) to see if it works, or explicitly set the path with jest.nodeEnv so you don't need to rely on any of the initialization...

@Chooks22
Copy link
Author

Chooks22 commented Feb 7, 2022

@connectdotz thanks for your time, launching vscode from a terminal indeed does inherit the envs, so somehow upgrading vscode changed something(?)

sadly, I couldn't just hardcode jest.nodeEnv since I rely on nvm to set the paths to node and stuff (unless there's a way to do that that I'm not aware of), so I just delegated initializing nvm a step higher than my ~/.zshrc file which is more of a hack but should be enough for my workflow.

I'll be closing this for now since it doesn't seem to be the extension's issue, thanks again for the help 👍

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

Successfully merging a pull request may close this issue.

2 participants