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

Most upvoted comments

@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_modules subdirectory, but it’s also using path.resolve, so relative paths worked for me, e.g.

{
  "reporter": "../node_modules/cypress-multi-reporters"
}

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 --reporter option is not specified.

For the below details, it’s useful to define some terms in this context:

  • project root: A folder that contains a cypress.json file and directories containing test specs, which is passed to cypress using the --project CLI option.
  • cypress root: The folder that contains the package.json file and node_modules folder 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 root first, and then either traverse through parent directories until it reaches cypress root, or else just check cypress root immediately after looking in project root (since it might not be safe to assume that project root is nested inside cypress 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 reporter a relative path and including it in the run options passed to cypress.run does 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 the cypress-test-nested-projects repo that caused the other error, but in any case I’m back in business for my specific situation. Thanks!