mbolotov / intellij-cypress

IntelliJ-Cypress plugin: https://plugins.jetbrains.com/plugin/13819-intellij-cypress Pro version: https://plugins.jetbrains.com/plugin/13987-cypress-support-pro
MIT License
35 stars 5 forks source link

Unable to run Cypress, command not found #72

Open willydee opened 2 years ago

willydee commented 2 years ago

Steps to reproduce

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 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

willydee commented 2 years ago

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 commented 2 years ago

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

mbolotov commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Sure. image

willydee commented 2 years ago

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 commented 2 years ago

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 commented 1 year ago

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 commented 1 year ago

Hi James,

Could you share a sample project to reproduce the problem?

jancellor commented 1 year ago

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 commented 1 year ago

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

jameschancellor commented 1 year ago

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 commented 1 year ago

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.