cypress: --reporter CLI option doesn't look in root node_modules folder
Current behavior:
I was trying to restructure my repo to be similar to https://github.com/cypress-io/cypress-test-nested-projects, with cypress and other node modules installed at the root instead of in the same folder as the cypress.json files.
However, I’m also passing the --reporter option to use cypress-multi-reporters, which now fails with the following error:
Could not load reporter by name: cypress-multi-reporters
We searched for the reporter in these paths:
- /home/<redacted>/<projectRootFolder>/<suiteFolder>/cypress-multi-reporters
- /home/<redacted>/<projectRootFolder>/<suiteFolder>/node_modules/cypress-multi-reporters
The error we received was:
Cannot find module '/home/<redacted>/<projectRootFolder>/<suiteFolder>/node_modules/cypress-multi-reporters'
Require stack:
- /home/<user>/.cache/Cypress/4.0.1/Cypress/resources/app/packages/server/lib/reporter.js
- /home/<user>/.cache/Cypress/4.0.1/Cypress/resources/app/packages/server/lib/project.js
- /home/<user>/.cache/Cypress/4.0.1/Cypress/resources/app/packages/server/lib/modes/run.js
- /home/<user>/.cache/Cypress/4.0.1/Cypress/resources/app/packages/server/lib/modes/index.js
- /home/<user>/.cache/Cypress/4.0.1/Cypress/resources/app/packages/server/lib/cypress.js
- /home/<user>/.cache/Cypress/4.0.1/Cypress/resources/app/packages/server/index.js
- /home/<user>/.cache/Cypress/4.0.1/Cypress/resources/app/index.js
-
Learn more at https://on.cypress.io/reporters
Desired behavior:
Cypress should also look further up the folder tree when a reporter package name is passed to the --reporter option, or there should be a CLI option to specify the node modules folder.
Test code to reproduce
I’ll work on adding a reproducible example tomorrow. I expect it would reproduce if you tried passing a --reporter option in the existing cypress run logic in https://github.com/cypress-io/cypress-test-nested-projects.
Versions
Cypress: 4.0.1
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 6
- Comments: 16 (2 by maintainers)
Commits related to this issue
- Reproducible test for cypress-io/cypress#6406 — committed to c32hedge/cypress-test-nested-projects by cjcrandall 4 years ago
- Reproducible test for cypress-io/cypress#6406 — committed to c32hedge/cypress-test-nested-projects by c32hedge 4 years ago
- Avoid Cypress' issue with JSON file reporter https://github.com/cypress-io/cypress/issues/6406 — committed to grafana/grafana by stevenvachon 4 years ago
- @grafana/e2e: Avoid Cypress' issue with JSON file reporter (#25092) https://github.com/cypress-io/cypress/issues/6406 — committed to grafana/grafana by stevenvachon 4 years ago
- @grafana/e2e: Avoid Cypress' issue with JSON file reporter (#25092) https://github.com/cypress-io/cypress/issues/6406 — committed to grafana/grafana by stevenvachon 4 years ago
@c32hedge I think I found a workaround! I looked in https://github.com/cypress-io/cypress/blob/9abed894eb1de3f81535cc13ec2775ed9d966c22/packages/server/lib/reporter.js#L516-L521
Looks like the reporter string is evaluated against the Cypress spec directory and its
node_modulessubdirectory, but it’s also usingpath.resolve, so relative paths worked for me, e.g.Hope that helps!
This also matches what’s described in the readme for cypress-test-nested-projects: https://github.com/cypress-io/cypress-test-nested-projects/blob/master/README.md. And it appears to work fine, if the
--reporteroption is not specified.For the below details, it’s useful to define some terms in this context:
project root: A folder that contains acypress.jsonfile and directories containing test specs, which is passed to cypress using the--projectCLI option.cypress root: The folder that contains thepackage.jsonfile andnode_modulesfolder that include Cypress.I did a little digging in the Cypress code based on the stack trace, and it looks like the code just gives up if it can’t find the reporter in the
project root.I think the behavior I would expect is that it would look in the
project rootfirst, and then either traverse through parent directories until it reachescypress root, or else just checkcypress rootimmediately after looking inproject root(since it might not be safe to assume thatproject rootis nested insidecypress root).This issue has been closed due to inactivity.
@emilong Interesting. I had tried the relative path approach previously, in my reproducible example, and got errors. However, since creating this issue we switched to calling Cypress using the module API from a script in the root of our repo, and I confirmed that giving
reportera relative path and including it in the run options passed tocypress.rundoes seem to work. I don’t know if the Cypress teams changed something in a more recent version that allowed this to work, if using the module API behaves differently, or if there’s something about thecypress-test-nested-projectsrepo that caused the other error, but in any case I’m back in business for my specific situation. Thanks!