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

extension default values are not correct in documentation #1170

Closed
armingjazi opened this issue Sep 7, 2019 · 3 comments
Closed

extension default values are not correct in documentation #1170

armingjazi opened this issue Sep 7, 2019 · 3 comments

Comments

@armingjazi
Copy link

to reproduce

https://github.com/tetrohed/nyc_react_coverage

Expected Behavior

all extensions mentioned in the documentation are picked up by nyc instrument

Observed Behavior

have to explicitly set extension: ['.js', '.jsx'] for 'jsx' to be picked up by the instrumenter

NOTE: the repo is setup with everything to reproduce, just remove extension: ['.js', '.jsx'] from nyc.config.js and run yarn run coverage you can see the file test.jsx is not present in insrumented folder

@Avaq
Copy link

Avaq commented Sep 8, 2019

I'm having the same issue with the .mjs extension.

Given:

  • src/
    • index.mjs: export default 42

I expect the following two scripts to produce the same result:

nyc --all -- node -p '"tests pass"'
nyc --all --extension .mjs -- node -p '"tests pass"'

But the first script produces:

tests pass
----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |        0 |        0 |        0 |        0 |                   |
----------|----------|----------|----------|----------|-------------------|

Whereas the second script produces:

internal/modules/cjs/loader.js:821
  throw new ERR_REQUIRE_ESM(filename);
  ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module

Note that the only thing I changed was the --extension flag, to add .mjs which is supposedly included by default. Since .mjs is in the default extension list, both scripts should have thrown the observed ERR_REQUIRE_ESM exception.

@Avaq
Copy link

Avaq commented Sep 8, 2019

I also just noticed that nyc --help shows an empty list as the default value for --extension.

@coreyfarrell
Copy link
Member

The README.md on github.com reflects the current state of master (what will become v15). Current release of nyc is 14.1.1, to read the README.md for the current release it's best to go to npmjs.com. See https://www.npmjs.com/package/nyc#common-configuration-options, in nyc 14.1.1 only .js files are instrumented by default. The additional extensions will be a feature of the next major release. You can monitor progress for the new release at #1104.

@Avaq please also note that native node.js ESM implementation does not support nyc. The native ESM implementation does not provide any hooks for transpiling code, so for nyc to work with native ESM you would need to pre-instrument all code. I hope the node.js team fixes this as it will effectively make @babel/register impossible to implement for native ESM. If you are working with native ESM you might want to check out c8.

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

3 participants