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

command not found: jest #899

Closed
taschetto opened this issue Aug 26, 2022 · 16 comments · Fixed by #941
Closed

command not found: jest #899

taschetto opened this issue Aug 26, 2022 · 16 comments · Fixed by #941

Comments

@taschetto
Copy link

Environment

  1. vscode-jest version: 4.6.0
  2. node -v: 14.20
  3. npm -v or yarn --version: 8.18.0
  4. npm ls jest or npm ls react-scripts (if you haven’t ejected):
[email protected] /home/taschetto/projects/org/backend
├─┬ [email protected]
│ └── [email protected] deduped
├── [email protected]
└─┬ [email protected]
  └── [email protected] deduped
  1. your vscode-jest settings if customized:
  "jest.autoRun": "off",
  "jest.jestCommandLine": "node_modules/.bin/jest", // same behavior when `undefined` or just `npm run tests`
  "jest.shell": "/bin/zsh" // same behavior when `undefined`
  1. Operating system: Ubuntu 22.04 LTS

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) npm run test

Steps to Reproduce

We have a monorepo with the following structure:

.
├── jest.config.js
├── node_modules
├── package.json
├── package-lock.json
├── packages
└── test

The extension works fine for projects inside packages/. But we also have a project at the root level . (CDK project, tests inside ./tests, can run tests in the terminal with npm run tests)

Whenever I try to run tests via the Text Explorer for that particular project, I get:

all-tests-56 is scheduled
zsh:1: command not found: jest

Expected Behavior

It should run the tests.

Actual Behavior

all-tests-56 is scheduled
zsh:1: command not found: jest
@taschetto
Copy link
Author

Installing jest as a global package seems to solve the issue, but I don't believe it's the best solution.

@connectdotz
Copy link
Collaborator

This sounds like a monorepo project set-up issue. Please take a look at the troubleshooting/jest-failed-to-run, particularly the monorepo projects section. Let me know if it helps.

@gedclack
Copy link

gedclack commented Sep 14, 2022

This also happen to me after updated my VSCode to the newest (Version: 1.71.1 (Universal)), my Test Editor also does not work anymore.

*I am using multi-root workspace.

Before updating my VSCode, all works fine, even the Test Editor shows correctly.

@taschetto
Copy link
Author

This sounds like a monorepo project set-up issue. Please take a look at the troubleshooting/jest-failed-to-run, particularly the monorepo projects section. Let me know if it helps.

The setup is correct.

@connectdotz
Copy link
Collaborator

@taschetto, I can take a deeper look if you can put together a sample repo.

@gedclack, does it return to normal if you restart code? I have seen the restart from the new vscode version sometimes caused shell env not to be initialized properly...

@connectdotz connectdotz added the need sample repo needs a sample repo to further investigate label Sep 15, 2022
@gedclack
Copy link

@connectdotz Yes! I am on MacOS, I need to quit VSCode and open it again. It does not work if I only Close the editor window.

@javifm86
Copy link

javifm86 commented Sep 30, 2022

Same here, but extension is not working, although I quit VS Code. I have a monorepo, everything was working fine (I configured some months ago).

I started getting this message around the end of August. Not only that, but I guess something has changed in VS Code, when I shut down my macOS (keeping my applications open for the next session), I get a warning message about some environment variable could not be initialized.

image

The problem is related to NVM (which I use), but if I restart VS Code that warning disappears and shell environment are loaded successfully.

But this is still there:

image

Just in case it can be related in any way. Maybe this information can help you, maybe not.

@connectdotz
Copy link
Collaborator

@javifm86 are you able to examine the process env of the spawned process? exit code 127 means "command not found", which usually indicates process.env is not fully set up as expected. See self-diagnosis for how to check process.env.

It is interesting that it was working fine until Aug...🧐

@javifm86
Copy link

javifm86 commented Oct 3, 2022

Sure. Today the frontend part is working fine (I would swear I checked it on Fridays, and it was not working), but the backend part is not working. Here you have the relevant information from DevTools for backend:

[Extension Host] [backend/ProcessSessionManager] scheduling jest process: list-test-files
{
    "ELECTRON_RUN_AS_NODE": "1",
    "USER": "ambes000083",
    "MallocNanoZone": "0",
    "__CFBundleIdentifier": "com.microsoft.VSCode",
    "COMMAND_MODE": "unix2003",
    "LOGNAME": "ambes000083",
    "PATH": "/Users/ambes000083/.nvm/versions/node/v16.13.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin",
    "SSH_AUTH_SOCK": "/private/tmp/com.apple.launchd.H7HAitRYTk/Listeners",
    "SHELL": "/bin/zsh",
    "HOME": "/Users/ambes000083",
    "__CF_USER_TEXT_ENCODING": "0x1F5:0x0:0x0",
    "TMPDIR": "/var/folders/0g/2kdy6xf13ddcgg5n1bxkdmyc0000gn/T/",
    "XPC_SERVICE_NAME": "application.com.microsoft.VSCode.28571057.28571063",
    "XPC_FLAGS": "0x0",
    "ORIGINAL_XDG_CURRENT_DESKTOP": "undefined",
    "VSCODE_CWD": "/",
    "VSCODE_NLS_CONFIG": "{\"locale\":\"en\",\"availableLanguages\":{},\"_languagePackSupport\":true}",
    "VSCODE_CODE_CACHE_PATH": "/Users/ambes000083/Library/Application Support/Code/CachedData/74b1f979648cc44d385a2286793c226e611f59e7",
    "VSCODE_IPC_HOOK": "/Users/ambes000083/Library/Application Support/Code/1.71.2-main.sock",
    "VSCODE_PID": "3100",
    "SHLVL": "0",
    "PWD": "/",
    "OLDPWD": "/",
    "ZSH": "/Users/ambes000083/.oh-my-zsh",
    "PAGER": "less",
    "LESS": "-R",
    "LSCOLORS": "Gxfxcxdxbxegedabagacad",
    "NVM_DIR": "/Users/ambes000083/.nvm",
    "NVM_CD_FLAGS": "-q",
    "NVM_BIN": "/Users/ambes000083/.nvm/versions/node/v16.13.1/bin",
    "NVM_INC": "/Users/ambes000083/.nvm/versions/node/v16.13.1/include/node",
    "_": "/Applications/Visual Studio Code.app/Contents/MacOS/Electron",
    "VSCODE_AMD_ENTRYPOINT": "vs/workbench/api/node/extensionHostProcess",
    "VSCODE_HANDLES_UNCAUGHT_ERRORS": "true",
    "APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL": "true"
}
[Extension Host] [backend/ListTestFileListener] not-test onExecutableStdErr: /bin/sh: jest: command not found
notificationsAlerts.ts:42 not-test onProcessExit: process exit with code=127, signal=undefined

@connectdotz
Copy link
Collaborator

connectdotz commented Nov 6, 2022

It seems vscode didn't initialize the process env completely. For people who frequently bumped into this issue, you can try switching to login shell added in v5 (still pre-release), and let us know if it resolved your issue.

if this works out well, we could even consider making the login shell the default. Then we don't need to rely on vscode's start-up initialization, which looked quite unstable...

This is a frequent complaint. We should either address the root cause or otherwise provide a self-help tool to diagnose and suggest possible solutions accordingly. Asking people to read documents just didn't seem very efficient. 🤔

@connectdotz connectdotz added enhancement and removed need sample repo needs a sample repo to further investigate labels Nov 6, 2022
@connectdotz
Copy link
Collaborator

@taschetto I looked at your original issue content more closely today, and noticed your comment:

 "jest.jestCommandLine": "node_modules/.bin/jest", // same behavior when `undefined` or just `npm run tests`

Not sure if it is a typo or a real problem, but you should set "jest.jestCommandLine": "npm run test --" to match how you run tests in the terminal. Your issue appeared to be different than the others in the thread, which is intermittent and most likely related to process.env.

Anyway, let us know if that resolves your issue.

@javifm86
Copy link

javifm86 commented Nov 7, 2022

This is a frequent complaint. We should eithe

Last Fridays it worked again, but today it is not working, therefore the initialization for VSCode is causing the problem. I will try the login shell.

Thank you for your time.

@connectdotz
Copy link
Collaborator

for people who landed here, we believe most of the issues have been addressed in v5 pre-release, please feel free to give it a spin and let us know otherwise.

@asifrahmanvm
Copy link

asifrahmanvm commented Jan 26, 2023

login shell

Using the pre-release version v5.2 but still same problem. Sometimes it works other times it doesn't.

@connectdotz
Copy link
Collaborator

@asifrahmanvm, what is the error message when it fails?

@clxrityy
Copy link

clxrityy commented Apr 1, 2024

I was encountering this error when trying to follow someone else's code, this is the example repo

Every time I ran pnpm i and/or pnpm update I was also getting a separate error.

By doing sudo pnpm i then sudo pnpm update, my pnpm test (jest watchAll --verbose), worked fine.

In short, I had to make sure the package was properly installed.

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

Successfully merging a pull request may close this issue.

6 participants