possible bug in cy.exec() - command not found: npm
See original GitHub issueCurrent 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
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:21 (4 by maintainers)
Top Results From Across the Web
cypress-io/cypress - Gitter
But I have run into a problem whit cy.exec(). ... Stderr: zsh:1: command not found: npm. The command cy.exec('echo test') works.
Read more >exec | Cypress Documentation
cy.exec() provides an escape hatch for running arbitrary system commands, so you can take actions necessary for your test outside the scope of...
Read more >Start script missing error when running npm start
I'm receiving this error when trying to debug my node application using the npm start command.
Read more >Cypress Best Practices For Test Automation - LambdaTest
This blog will teach you the Cypress best practices to write reliable and high-quality test codes while performing Cypress testing.
Read more >cypress-parallel - npm
Run your Cypress tests in parallel (locally). How it works. - Search for existing Cypress tests - Read (if exists) a weight file...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
sleep
works 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.exec
works.Changing your VS Code terminal from Bash to Powershell solves the issue.