nyc test coverage not working when type:module is activated
See original GitHub issueExpected Behavior
After I’ve changed my package.json to type:module, the coverage report stopped working. All tests have passed but the report hasn’t been generated. Previously I’ve used the esm module which works fine. Someone experienced the same problem?
Observed Behavior
186 passing (9s)
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
Terminal will be reused by tasks, press any key to close it.
Troubleshooting steps
- still occurring when I put
cache: false
in my nyc config
Environment Information
package.json
"scripts": {
"test": "cross-env NODE_ENV=test nyc --reporter=text-summary ./node_modules/mocha/bin/mocha test --recursive",
"coverage": "cross-env NODE_ENV=test nyc --reporter=html --reporter=text ./node_modules/mocha/bin/mocha test --recursive",
},
"type": "module",
Issue Analytics
- State:
- Created 3 years ago
- Reactions:13
- Comments:11 (2 by maintainers)
Top Results From Across the Web
Minimalistic nyc (istanbul) javascript coverage not working for ...
I start getting coverage output when not using "type": "module" in my package.json . Versions: node: v16.13.2; nyc: 15.1.0. javascript · es6- ...
Read more >CLI - Node Tap
This requires coverage to be enabled, because tap uses NYC's process info tracking to monitor which file is loaded by which tests. If...
Read more >the requested profile "coverage" could not be activated ...
After I've changed my package.json to type:module, the coverage report stopped working. All tests have passed but the report hasn't been generated.
Read more >What are y'all using for test coverage? - ReScript Forum
I've been using nyc with ReScriptTest and it was working well in CommonJS. I tried to convert a project today to ES6 in...
Read more >T212521 RFC: Reconsider how we run QUnit unit tests
Yet Selenium (despite having its own problems) is meant for integration ... It is very difficult to add code coverage for JS when...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m one such developer. 👋
I was trying to use ava@3.15.0 with nyc@15.1.0 with
"type": "module"
inpackage.json
with node@14.17.6. Got this output on runningnyc ava
. I have created a minimal reproduction for this as well.@istanbuljs/esm-loader-hook
didn’t work out for me. The coverage output reported by nyc didn’t budge.I resolved it by swapping out nyc with
c8
& it worked like a charm. It works for my purposes, so I’ll stick with c8 for the time being. Though, would appreciate if nyc worked out of the box with esm as well.After some digging it appears this has been a known issue for months with no solution. There is some discussion on using
c8
instead, which worked well for me in testing:https://github.com/istanbuljs/nyc/issues/1343