Skip to content

Allow for declaring the nycrcPath to use custom-named configuration files. #967

@hammzj

Description

@hammzj

Is your feature request related to a problem? Please describe.
Right now, this plugin supports loading default named ".nycrcfiles, but cannot utilize a custom named one, like.nycrc.config.cypress.js`. An option to provide custom configuration options exist for other test frameworks, like vitest.

Specifically in the case I am using, I need to have distinct outputs between unit and component test coverage, where Vitest handles unit tests, and Cypress handles component tests. This is due to limitations of how Cypress handles source maps versus Vitest where line lengths do not align properly (and this is well-documented in this repo and in the official nyc repo as well). To avoid that issue, I need separate .nycrc configs for both test frameworks.

Cypress currently only supports default named .nycrc files, or a configuration defined in the package.json, but this limits how we can use nyc as it prefers the configuration used for Cypress over any other configurations that can exist. This is a problem if we need to merge results and report on total coverage combined by both, running nyc report will ignore the files matched in the unit test configuration.

Describe the solution you'd like
The plugin should allow for calling a custom nycrcPath when being declared in the Cypress configuration, either by config.nycrcPath or config.env.nycrcPath.

For an example, see here:
https://github.com/iFaxity/vite-plugin-istanbul?tab=readme-ov-file#istanbulplugin--opts--

Describe alternatives you've considered
I will need to use three .nycrc configurations which is incredibly messy:

  • .nycrc.config.mjs, a default config used only for accurate reporting of merged component + unit test code coverage results. This would be called in a command like npx nyc report --nycrc-path=./.nycrc.config.mjs. Specifying the path is necessary here.
  • .nycrc.config.component.mjs, a Cypress-specific configuration extended from the default; it must be loaded as part of the package.json using "nyc": { "extends": "./.nycrc.config.component.mjs" }. Running npx nyc report without declaring the path will utilize this config instead of the default, which is the main issue.
  • .nycrc.config.unit.mjs for Vitest files only.

Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions