cypress: possible bug in cy.exec() - command not found: npm
Current behavior:
CypressError: cy.exec('npm run db:reset') failed because the command exited with a non-zero code.
Pass {failOnNonZeroExit: false} to ignore exit code failures.
Information about the failure:
Code: 127
Stderr:
zsh:1: command not found: npm
Because this error occurred during a 'before each' hook we are skipping the remaining tests in the current suite: 'deleteUser'
After clicking on “Run all tests” (reload button) it works fine. It just does not work on the first time.
When I tried to provide PATH as an env option to cy.exec() it was doing the same thing.
Desired behavior:
Running cy.exec even on the first time, not just every time after the first time
Steps to reproduce: (app code and test code)
- npm run cy:open
- click on the test that is using cy.exec()
- it fails
- click on “Run all tests” (reload button)
- the same test now works fine
Versions
“cypress”: “^3.8.1” in package json as a dev dependency macOS catalina
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 6
- Comments: 22 (4 by maintainers)
Just chiming in to say we were debugging something similar today…
Context:
We have a command (
prep), frequently run in abeforeAll, that looked something like this:The first time
cy.prep()was run, it would fail with the error described in this issue (Code: 127,command not found: npm). But when run before subsequent tests in the suite, it would pass.In debugging, we saw that adding another exec command (pwd, sleep, whatever) seemed to prevent it from breaking. For example, this version with a
sleepworks every time:I can’t reproduce it on my machine, only on another developer’s laptop.
She’s using Bash as her default shell and High Sierra, fwiw.
Could this be an issue with nvm (perhaps login scripts/shimming is not yet complete)? I have no idea how
cy.execworks.Changing your VS Code terminal from Bash to Powershell solves the issue.
I had a similar issue, a solution was: Doing
which npmon your system may give youuser/local/bin/npm. Then, in cypress, before calling npm, just doexport PATH=/usr/local/bin/:$PATH@michalvankodev, I come against a similar behaviour as yours. Mine was a dependency issue, solved on Node 14
What I found that may interest you:
npm, likecy.exec('npm run db:empty');heresh(dash) shell, not the default login shell (for me,zsh), the one you set withchsh(you can check this by insertingps -p $$in your npm script)I quick-fixed it by installing Node on OS level, as I haven’t been able to install
nvmondashSo why cypress use
shinstead ofzsh? The shell is picked here using $SHELL environment variables, themselves provided by shell-env dependency.So I can’t figure why:
zsh($SHELL iszsh)shin $SHELLThe answer may lay in
shell-envdependency, default-shell@jennifer-shehane i don’t have
nodeVersionset in mycypress.json. it’s bare bones: