jest-community / vscode-jest

The optimal flow for Jest based testing in VS Code
MIT License
2.82k stars 291 forks source link

[BUG] vscode-jest not waiting for environment variable resolution #1125

Closed alexrecuenco closed 3 months ago

alexrecuenco commented 3 months ago

Describe the bug If I start vscode by opening a window (macOS) vscode-jest executes instantly, before waiting for environment variables to resolve.

When that happens it returns

vscode jest [warn] possible process env issue detected, restarting with a login-shell...

And it tries to use /bin/bash as a backup (Even though /bin/zsh is my default terminal

To Reproduce Steps to reproduce the behavior:

  1. Set "application.shellEnvironmentResolutionTimeout": 120

  2. Write in your login shell script (.zshrc/ .bashrc/ etc) sleep 2

  3. Open a new window (not by running code . but by opening a workspace with code, I tried in my case with double clicking a .code-workspace file

  4. See error above

  5. Close that window

  6. Open a new window with code .

  7. The error is no longer happening.

Expected behavior vscode-jest should wait for shell environment resolution before it tries to run, this extension starts faster than any other, and maybe too fast

If you use

Screenshots If applicable, add screenshots to help explain your problem.

❯ nvm --version
0.39.5
❯ node -v
v18.18.0

VERSION
        "jest": "^29.6.2",

settings.json
    "jest.jestCommandLine": "npm test -- ",
    "jest.runMode": {
        "type": "on-demand",
    },

Prerequisite

Additional context

If you start a new window with code . it works, since environment resolution happens before you open the window


connectdotz commented 3 months ago

@alexrecuenco, do you happen to have "jest.shell" defined? Otherwise, it will default to 'bash' when trying to run a login-shell as you have discovered.

I guess we could enhance the extension to read vscode setting for the shell used by the terminal... but let's first make sure the "jest.shell" works for your use case.

Regarding activating too early. It's not clear to me that there is a way to "wait" until the shell is fully initialized, as far as I know. The solution is usually just to start a "login shell" so the spawned jest process can initialize the env itself without relying on the parent process's env (vscode).

alexrecuenco commented 3 months ago

I am sorry, I am having a hard time reproducing this issue on the newest update. I am not sure if it was resolved, or if something about the workspace I am using is loading jest differently now.

connectdotz commented 3 months ago

that's all right. I am going to close it for now. Feel free to re-open it If you experience the same problem again and setting jest.shell did not work.