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

Unable to run Cypress, command not found #72

Open
willydee opened this issue Nov 19, 2021 · 18 comments
Open

Unable to run Cypress, command not found #72

willydee opened this issue Nov 19, 2021 · 18 comments

Comments

@willydee
Copy link

willydee commented Nov 19, 2021

Steps to reproduce

  • Run Webstorm/IntelliJ on a Linux machine with GNOME/Wayland
  • Install the Cypress Support plugin
  • Create a Run Configuration as shown in the screenshot

Screenshot Run Configuration

Expected result

Cypress should be launched

What happens instead?

Console output

/usr/bin/node /usr/lib/node_modules/yarn/bin/yarn.js run cypress run -b firefox --headed --reporter /tmp/intellij-cypress-reporter1060372266017381373.js --spec /home/willy/Projects/control-panel/apps/control-panel-cyv/src/integration/**/*
yarn run v1.22.17
error Command "cypress" not found.

System info

OS: Arch Linux x86_64
Kernel Release: 5.15.2-arch1-1
Windowing System: X11 on Wayland
DE: GNOME Version 41.1
RAM: 7530 MB / 31729 MB
Processor Type: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Root: 207G / 723G (28%) (ext4)

Application versions

WebStorm 2021.3 EAP (213.5744.37)
Cypress Support Pro (Trial) 2.5.1-2021.3
Cypress package version: 8.3.0
Cypress binary version: 8.3.0
Electron version: 13.1.7
Bundled Node version: 14.16.0

Path to Cypress executable

$HOME/Projects/control-panel/node_modules/.bin/cypress

Additional info

Our project structure is perhaps not the usual setup, due to requirements of the CI. Cypress itself is installed in the node_modules of project root; the binary is correctly located in node_modules/bin. But it is not found because that directory is not part of the user's $PATH, and in Wayland it is notoriously hard to get any additional directory into the session path. Using Node Version Manager triggers similar troubles, so I had to completely ditch it a while ago.

WebStorm itself has a setting for its integrated terminal: ☑ Add 'node_modules/.bin' from the project root to $PATH, so that cypress can be run seamlessly from the built-in terminal. I have no idea why such an option is not generally available in Run/Debug Configurations; IMHO it would be very useful. But maybe a checkbox like that can be integrated into the plugin's configuration?

@mbolotov
Copy link
Owner

mbolotov commented Dec 3, 2021

@willydee, could you somehow share a sample project to reproduce the issue?
it's not a big deal to add an option to modify the $PATH but I need a sample to verify your problem is fixed.

@mbolotov
Copy link
Owner

mbolotov commented Dec 3, 2021

if it's not possible, I can provide you a (not tested) plugin snapshot with the option added and you can check it in your environment.

@willydee
Copy link
Author

willydee commented Dec 3, 2021

I think that's the faster way, since I'm not so familiar yet with setting up a complex project like the one used by our team. I'll happily test a snapshot.

@mbolotov
Copy link
Owner

mbolotov commented Dec 3, 2021

here is a snapshot:
Cypress Support Pro-2.5.2-SNAPSHOT.zip

@willydee
Copy link
Author

willydee commented Dec 3, 2021

Mike, the plugin successfully installed after downgrading Webstorm form 213.x to 212.x. cypress is correctly found in node_modules/.bin.

Still I have troubles getting tests to launch; looks like an assumption is made that everything is located relative to the project root; all paths are expanded from there. Our Cypress project is located in a subfolder <PROJECT_ROOT>/apps/control-panel-cy, which I correctly entered into the Cypress project base field. The file cypress.json is assumed to be in the project root:

$ /home/willy/Projects/control-panel/node_modules/.bin/cypress run -b chrome --headed --reporter /tmp/intellij-cypress-reporter11003797996885613353.js --spec /home/willy/Projects/control-panel/apps/control-panel-cy/src/integration/...
Could not find a Cypress configuration file, exiting.

We looked but did not find a cypress.json file in this folder: /home/willy/Projects/control-panel

If I specify the full path in the Program arguments, the config file is found, but again, all paths are expanded relative to the project root instead of the specified Cypress project base:

$ /home/willy/Projects/control-panel/node_modules/.bin/cypress run -b chrome --headed --config-file apps/control-panel-cy/cypress.json --reporter /tmp/intellij-cypress-reporter11003797996885613353.js --spec /home/willy/Projects/control-panel/apps/control-panel-cy/src/integration/...
The support file is missing or invalid.

Your `supportFile` is set to `/home/willy/Projects/control-panel/src/support/index.ts`, but either the file is missing or it's invalid. 

Relevant entry in cypress.json:

  "supportFile": "./src/support/index.ts"

Maybe I'm just missing or misunderstanding a config option...

@willydee
Copy link
Author

willydee commented Dec 3, 2021

My last run configuration (project root is /home/willy/Projects/control-panel):
image

@mbolotov
Copy link
Owner

mbolotov commented Dec 3, 2021

It's a bit hard for me to calculate all the paths without a sample directory structure..
Anyway, how do you run the tests from command line?

@willydee
Copy link
Author

willydee commented Dec 3, 2021

That's what our project structure basically looks like (the relevant parts):

<PROJECT_ROOT>/
  apps/
    control-panel/       # the Angular application source tree
    control-panel-cy/    # the Cypress end-to-end tests (supposedly `Cypress project base`)
      src/
        integration/     # contains the `Test files` grouped in subdirectories
        pages/
        plugins/
        support/
      cypress.json
  node_modules/
    .bin/
      cypress            # the Cypress executable
  angular.json
  packages.json
  ...

To run Cypress from command line, we do (assuming node_modules/.bin is part of $PATH):

$ cd <PROJECT_ROOT>/apps/control-panel-cy
$ cypress open

Hope this is of help to you.

@mbolotov
Copy link
Owner

mbolotov commented Dec 3, 2021

Hmm, I've recreated your project structure.
But I'm unable to reproduce the problem, probably because I'm on Windows.
Could you also share the Runner tab of your run configuration?

@willydee
Copy link
Author

willydee commented Dec 6, 2021

Sure.
image

@willydee
Copy link
Author

willydee commented Dec 6, 2021

For completeness (although not involved), the package.json commands we're using to launch Cypress outside the IDE environment:

    "e2e:cypress:open": "cypress open --project apps/control-panel-cy --browser chrome",
    "e2e:cypress": "cypress run --project apps/control-panel-cy --browser chrome",
    "e2e:cypress:ci": "cy2 run --record  --key notNecessaryWithSC --project apps/control-panel-cy --browser chrome --parallel",

@mbolotov
Copy link
Owner

mbolotov commented Dec 8, 2021

hey @willydee,
could you try to add --project apps/control-panel-cy to you run configuration and check if it helps?

image

Also, it seems you should set the cypress project base to this:
image

@jameschancellor
Copy link

jameschancellor commented Feb 27, 2023

Er, I know this is over a year old. But for what it's worth I had exactly the same problem and your last suggestion @mbolotov to add the program argument --project <path-to-cypress-workspace> works. It does not seem to matter what the Cypress project base is set to. This was confusing for me.

I would expect the Cypress project base to works since it seems specifically intended for that (and program arguments is just for random other options not supported directly by the plugin UI presumably). Also when clicking on the "play" icon in a test to automatically create a run configuration, the Cypress project base gets correctly auto-filled, so it would be nice if the configuration worked without any further tweaking.

I'm just happy I have an option to run Cypress tests in an integrated way in the IDE.

@mbolotov
Copy link
Owner

Hi James,

Could you share a sample project to reproduce the problem?

@jancellor
Copy link

Sure, here: https://github.com/jancellor/cypress-test-yarn

I struggled to reproduce at first but I think the key thing is if it is yarn 1 project. I tried first with npm 9 and the config file is found fine.

In the run window I either see a single line for npm:

/home/.../.nvm/versions/node/v16.19.1/bin/npx cypress run --e2e ...

which works fine or multiple lines for yarn:

/home/.../.nvm/versions/node/v16.19.1/bin/yarn run cypress run
yarn run v1.22.19
$ /home/.../dev/cypress-test-yarn/node_modules/.bin/cypress run
Could not find a Cypress configuration file in this folder: /home/.../dev/cypress-test-yarn

@mbolotov
Copy link
Owner

mbolotov commented Mar 9, 2023

@jancellor
how to reproduce the problem using the cypress-test-yarn repo?
it seems it has no any cypress stuff.

@jameschancellor
Copy link

Apologies must have forgotten to commit (on a different machine now). Repository is updated. Open the project in the IDE, do a yarn install, open the file packages/app-e2e/src/e2e/app.cy.ts, click on the play sign, choose Run > cy option.

@JKapitein
Copy link

FWIW, most if not all of these could be fixed (I think) by allowing customisation of the command used to invoke Cypress. For example, I use npx nx cypress-run {project} in our monorepo. yarn run cypress open won't work for us.

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

No branches or pull requests

5 participants