-
-
Notifications
You must be signed in to change notification settings - Fork 360
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 on ESM Node.js 13 (no babel) #1287
Comments
I'm seeing the same problem with mocha. nyc reports 0 coverage for native esm. (node 12 with |
nyc does not yet support coverage of node.js native ESM. It will take some time as node.js has just created API's to make this possible though they are still experimental and subject to breakage. I'm working on creating an FWIW it looks like the currently available ESM transform hook is available in node.js |
Thank you @coreyfarrell . Looking forward. |
For anyone interested please see https://github.com/istanbuljs/esm-loader-hook#readme. To be very clear this is experimental. |
Any update for when this will be added to NYC without an additional loader? |
This will not be considered until after the node.js loader feature is no longer experimental. |
This comment has been minimized.
This comment has been minimized.
This issue is about node.js native ES modules, if you are using the user-space |
@coreyfarrell Thanks for your answer. |
@coreyfarrell thanks a lot for your answer! |
@pandres95 it's a complex set of issues being worked in node.js itself, there is nothing to be done on this end. It's not possible to accelerate progress . I fully expect it will be months before I'm able to consider including |
Okay. Will wait until that happens, then. I tried using |
I'm sure @bcoe would appreciate a report on c8 if you can provide a reproduction. |
Relates to istanbuljs/nyc#1287
Hi, I'm trying to use Nyc with Typescript on ESM, and it doesn't seem it works as well. ( I anyway tried the loader Here is my current package.json. And with the usage of nyc: {
"scripts": {
"test": "node --experimental-specifier-resolution=node --experimental-modules --loader ts-node/esm node_modules/mocha/lib/cli/cli.js src/**/*.test.ts",
"test:code-coverage": "nyc npm run test",
},
"devDependencies": {
[...]
"nyc": "^15.1.0",
}
} It produces this result:
At this point I just don't know what to do or what to try :(. As I'm not sure the problem is the same, I can create another issue if you prefer. |
Hey it was mentioned that this would not be implemented natively till the point where ESM is stable in Node. That time has come. It is now stable. What is the ETA for this to be supported officially by Istanbul/NYC? |
To my knowledge the situation has not changed, the specific issue is that ESM loader hooks need to be stable. This is a separate feature on top of ESM itself. |
Okay but realistically speaking... Do we actually expect any change within those? Why is Nyc/Istanbul not aligning now and then just refine if changes are happening within ESM? More and more projects are using the ESM syntax out of the box and nobody likes to fiddle with configs and extra packages for coverage. I don't want to sound passive-aggressive but this would make a huge difference in every ones life. |
Yes, we expect the istanbul provides an experimental plugin which you can use if you want (I use it in many side projects). nyc absolutely will not be integrating this plugin until after the feature is stable. |
okay, makes sense. Thanks for the insight. |
Node 15 is current and esm support is stable there ... or am I missing something?! Are their any updates? |
Yeah I have the same question, ESM is stable and is being used in production. How do we get nyc working with it? |
I am using node native esm (use import instead of require). |
|
You can use c8 instead of nyc or follow the instructions at @istanbuljs/esm-loader-hook to get coverage from nyc on projects with To repeat myself, the |
I get the same issue with
nyc ava && nyc report --reporter=text-lcov I am not sure if it is caused by this problem:
The problem can be reproduced here |
Currently non-functional (istanbuljs/nyc#1287).
* nyc does not yet support ESM istanbuljs/nyc#1287
Hi! I'm running coverage on a server driven from outside through its API.
Thanks for your help! |
Well, unfortunately solved by moving to |
@crystalfp I hadn't luck with both of them. See also bcoe/c8#244 . |
In case this helps some future traveler, I did get this working with the following config: package.json (just the relevant parts): {
"devDependencies": {
"@types/mocha": "10.0.1",
"@istanbuljs/nyc-config-typescript": "1.0.2",
"@istanbuljs/esm-loader-hook": "0.2.0",
"mocha": "10.2.0",
"nyc": "15.1.0",
"ts-node": "10.9.1",
"typescript": ">=5.0.4"
},
"scripts": {
"test": "ts-node-esm ./node_modules/.bin/mocha '**/*.test.ts'",
"test:coverage": "ts-node-esm ./node_modules/.bin/nyc mocha **/*.test.ts"
},
"type": "module",
"nyc": {
"extends": "@istanbuljs/nyc-config-typescript",
"check-coverage": true,
"all": false,
"include": [
"src/**/!(*.test.*).[tj]s?(x)"
],
"exclude": [
"src/_tests_/**/*.*"
],
"reporter": [
"html",
"lcov",
"text",
"text-summary"
],
"report-dir": "coverage"
}
} .mocharc.json: {
"node-option": [
"no-warnings",
"experimental-specifier-resolution=node",
"loader=@istanbuljs/esm-loader-hook",
"loader=ts-node/esm"
]
} I've got mine set up in run as a Mocha task in IntelliJ with no special config, beyond just setting it to "File Patterns" and I can confirm:
Also, I have nyc set to |
Now that the Chai assertion library at version 5.0 (December 2023) and above uses ES syntax, supporting this needs to be NYC's top priority even if the fix is a cludge for now until NodeJS stabilizes the relevant parts. At this point the can cannot be kicked down the road any more as we are at the point that NYC may just cease to be relevant. |
Does
nyc
work with ESM and Node.js 13 without babel?I followed the steps from https://github.com/avajs/ava/blob/master/docs/recipes/code-coverage.md
My config from
package.json
isWhen I run the coverage script I get this:
I don't use babel, and imports are done with
import
notrequire
.I'm on the latest versions of node.js, ava, nyc
The text was updated successfully, but these errors were encountered: