-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
possible bug in cy.exec() - command not found: npm #6081
Comments
@zsolt-dev I'm not able to reproduce this error. Please provide the exact test code.
"scripts": {
"foo": "echo foo"
}, it('exec npm', () => {
cy.exec('npm run foo').then((obj) => {
cy.log(obj.code)
cy.log(obj.stdout)
cy.log(obj.stderr)
})
}) |
I saw this issue and noticed OP is using zsh as their shell (which is the new default on macOS catalina). I'm also using zsh on ubuntu and had the same issue. I don't have the issue when switching my default shell back to bash with |
I also use zsh as my shell (on Catalina) and am unable to reproduce the issue from the code I pasted above. Unfortunately we'll have to close this issue if no reproducible example is provided. Please provide the test code to run to reproduce this error. |
This is an issue I am also running into with Catalina, zsh, and executing npm commands through Cypress. I am also using If I run "scripts": {
"foo": "echo foo"
}, Startup script I am using: import { exec } from 'child_process'
exec('npx cypress run', (error, stdout, stderr) => {
if (error) console.error(error)
console.log(stdout)
console.error(stderr)
}) Cypress test: it('should echo foo', () => {
cy.exec('npm run foo')
}) Gives me an error |
@jennifer-shehane updated my description with minimal code to reproduce as best I can. |
Just chiming in to say we were debugging something similar today… Context: We have a command ( Cypress.Commands.add("prep", () => {
cy.exec("npm run prep");
}); The first time In debugging, we saw that adding another exec command (pwd, sleep, whatever) seemed to prevent it from breaking. For example, this version with a Cypress.Commands.add("prep", () => {
cy.exec("sleep 1");
cy.exec("npm run prep");
}); 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 |
We use This is essentially the exec code: https://github.com/cypress-io/cypress/blob/develop/packages/server/lib/exec.js#L18:L18 |
Funny as it sounds. I get this error as well when the failing tests runs for the first time only. and yes I also use
In both environments the problem is the same: It only works on second try. Hopefully my little hack will work by executing the command before all tests, let it retry and pass. and then it shouldn't require setting retries anymore. |
I have this same issue too. |
i had the same issue as well. i was on nvm 0.33.11. i upgraded to the latest version (0.37.2 as of writing) and that seems to have solved my problem. |
Are any of you setting |
@jennifer-shehane i don't have {
"baseUrl": "http://localhost:3000/"
} |
@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:
I quick-fixed it by installing Node on OS level, as I haven't been able to install So why cypress use So I can't figure why:
The answer may lay in |
I had a similar issue, a solution was: |
I'm having the same issue, and maybe this is a good reference. Github Repo |
updating the nvm to the version solved the issue for me. Thanks to @dlcoffee for providing the fix in the comment. |
I am encountering this issue as well. I have attempted your example: |
Changing your VS Code terminal from Bash to Powershell solves the issue. |
I have the same issue and have to add "source ~/.zshrc" to all exec commands for nvm/Node to work. So it seems that Cypress doesn't actually run the zshrc file even when using zsh? I checked using echo $0 and it is using zsh. |
I think I have almost the same problem under Mac OSX, using Cypress standalone / direct download. I'm using Depending on how Cypress is launched, the
|
@alexsegura I also facing the same issue, have you solved it? |
I am using this npm script to open cypress: Thanks to the comments above, I was able to fix this issue by adding SHELL=/bin/bash to the script: |
Current behavior:
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)
Versions
"cypress": "^3.8.1" in package json as a dev dependency
macOS catalina
The text was updated successfully, but these errors were encountered: