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

Loading 'nyc' config broken with Cypress 10.x #586

Open
jhpedemonte opened this issue Aug 9, 2022 · 6 comments
Open

Loading 'nyc' config broken with Cypress 10.x #586

jhpedemonte opened this issue Aug 9, 2022 · 6 comments

Comments

@jhpedemonte
Copy link

Logs and screenshots

Versions

  • What is this plugin's version? latest
  • If the plugin worked before in version X, but stopped after upgrading to version Y, please try the released versions between X and Y to see where the breaking change was.
  • What is Cypress version? 10.4.0
  • What is your operating system? MacOS 12.5
  • What is the shell? bash
  • What is the Node version? 16.3.1
  • What is the NPM version? 8.3.2
  • How do you instrument your application? @cypress/instrument-cra
  • When running tests, if you open the web application in regular browser, and open DevTools, do you see window.__coverage__ object? Yes
  • Is there .nyc_output folder? Is there .nyc_output/out.json file. Is it empty? Can you paste at least part of it so we can see the keys and file paths?
  • Do you have any custom NYC settings in package.json (nyc object) or in other NYC config files. Yes, in package.json
  • Do you run Cypress tests in a Docker container? Yes, but issue is also seen locally, outside of Docker container

Describe the bug

This plugin no longer reads the 'nyc' config inside of {project root}/package.json. This appears to be due to changes in Cypress 10.0: now, the Cypress config file is loaded in a child process with cwd set to the parent dir of the config file, rather than the project root. That means that this code in this plugin will try to load {cypress config dir}/package.json (which doesn't exist for me and probably many others) instead of the on at project root, like with Cypress 9.x.

cypress-io/cypress#22689 has a few more details, including reproduction repo.

Link to the repo
See cypress-io/cypress#22689

@jhpedemonte
Copy link
Author

jhpedemonte commented Aug 9, 2022

Looks like plugin could be updated to use config.projectRoot instead of process.cwd().

@AriPerkkio
Copy link

Before the upstream issue is resolved I don't think anything should be done to @cypress/code-coverage codebase.

As work-around you should be able to place a .nycrc next to cypress.config.ts and configure everything there, e.g.

<project-root>
└── config
   └── cypress
      ├── .nycrc
      ├── component-index.html
      ├── cypress-support.ts
      └── cypress.config.ts

Here's how I'm generating coverage results into project root, config/cypress/.nycrc:

{
    "report-dir": "../../test-results/cypress/coverage",
    "temp-dir": "../../test-results/.nyc_output"
}
"cypress run --component --config-file config/cypress/cypress.config.ts"

@jhpedemonte
Copy link
Author

Agreed, need someone from Cypress to chime in. In the meantime, I have a different workaround I'm currently using, which mimics the previous (9.x) behavior: cypress-io/cypress#22689 (comment)

@thedaaron
Copy link

Can you also load nyc.config.cjs?

@shandav
Copy link

shandav commented Sep 22, 2022

The workaround for creating a .nycrc in the root directory seems to be working for me, although it seems to be partially working. check-coverage: true seems to be picked up by Cypress, but the all: true option isn't working for me (I'm trying to get coverage for source files that aren't loaded during tests).

Not sure if this is the same issue, where it doesn't see the all option, or if the all option isn't working with my setup / Cypress.

This is my .nycrc file:

{
    "all": true,
    "extends": "@istanbuljs/nyc-config-typescript",
    "check-coverage": true
}

@aantes-st
Copy link
Contributor

I wonder if the nyc config location could be made to be configurable via Cypress configuration options?

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