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

nyc.config.js in "type": "module" project #26729

Closed
robrich opened this issue May 11, 2023 · 1 comment
Closed

nyc.config.js in "type": "module" project #26729

robrich opened this issue May 11, 2023 · 1 comment
Assignees

Comments

@robrich
Copy link

robrich commented May 11, 2023

Current behavior

Goal: Cypress e2e coverage and Cypress component coverage don't overwrite each other.

or

Goal: Single coverage report covering both e2e & component tests.

Repro steps:

  1. set package.json: "type": "module"
  2. create dynamic config: nyc.config.js file with any options
  3. run cypress tests: npx cypress run --browser chrome && npx cypress run --browser chrome --component

Expected behavior:

It loads the nyc.config settings then runs the test

Actual behavior:

ReferenceError: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and 'C:\path\to\my\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///C:/path/to/my/nyc.config.js:8:1
    at ModuleJob.run (node:internal/modules/esm/module_job:192:25)

or

Error: Failed to load nyc.config.js: require() of ES Module C:\path\to\my\nyc.config.js from C:\path\to\my\node_modules\@cypress\code-coverage\task-utils.js not supported.

Attempted work-arounds:

  • Rename config to nyc.config.cjs: doesn't pick up config
  • Rename config to nyc.config.ts: doesn't pick up config
  • Change file content to ES6 module syntax: different error, but still errors

Desired behavior

No response

Test code to reproduce

see above

Cypress Version

12.11.0

Node version

20.1.0

Operating System

Windows 11

Debug Logs

No response

Other

No response

@mike-plummer
Copy link
Contributor

@robrich Thanks for the report, and sorry you're having issues. There are so many landmines with these new module types.

This is really an issue with @cypress/code-coverage due to its unguarded use of require(..). I opened a new issue over there cypress-io/code-coverage#668 and will close this one in favor of that.

I'm assuming you tried to sort out a way to use the non-dynamic config via package.json or .nycrc, but I suppose it's tricky given the use case you're trying to fulfill. The only workaround that springs to mind is to do the instrumentation step manually and pass custom CLI params to nyc for each set of source files to use a different report-dir - it would work, but would be a bit of a pain

@mike-plummer mike-plummer closed this as not planned Won't fix, can't repro, duplicate, stale Jun 21, 2023
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

4 participants