code coverage with nyc fails to cover all paths when using rewire@3
See original GitHub issueExpected Behavior
nyc
should cover all test paths when using rewire@3
as a monkey-patching tool
Observed Behavior
When in a project that has a dependency on rewire@3
, nyc
will sometimes not report all the covered code that gets executed. This behavior does not occur when using rewire@2
or when using istanbul@0.4.5
Bonus Points! Code (or Repository) that Reproduces Issue
I am not entirely clear on what exactly causes this issue. It doesn’t happen all the time that rewire is being used, and load order of the files seems to matter.
Below is a repository I created that reproduces the issue in a relatively small number of files. https://github.com/bforbis/istanbul-rewire-test
Forensic Information
Operating System: macOS Sierra Environment Information:
- node version: 8.9.1
- npm version: 5.5.1
NYC issue tracker
This issue has been cross posted to the nyc github at istanbuljs/nyc/issues/747
Issue Analytics
- State:
- Created 6 years ago
- Reactions:14
- Comments:12 (3 by maintainers)
Top Results From Across the Web
Error getting the coverage report with rewire / cross-env
I've found a solution on this issue playing around the babel configuration file and the plugins. To avoid this case would be better...
Read more >Testing Error Handling in node.js | by Lars Trieloff
json 's test script, I set up nyc , which generates test coverage reports with the following options: --reporter=text creates a nice textual...
Read more >Add Test Coverage to your Serverless Applications
Test coverage (or code coverage) is a measure used to describe the degree to which the source code of a program is executed...
Read more >Cypress code coverage for applications created using create ...
Creating a new fully featured React application using Create React App v3 is as easy as two NPM commands $ npm i -g...
Read more >Code coverage testing - Visual Studio (Windows)
To determine what proportion of your project's code is being tested by coded tests such as unit tests, you can use the code...
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
Can you provide a minimal reproducible example? 😃 That would help me to track down the bug.
@jhnns I just confirmed that this has fixed the issue in my linked test repository. I also tested it on several of my private repos and saw that upgrading from
rewire@2
torewire@4
correctly preserves the code coverage fromnyc
, so looks like everything is working.I’ll note that in one of my repos I did start seeing an issue with running mocha/nyc of this nature:
I don’t have a minimum reproduction I can share that caused this, but I was able to fix this issue by updating my mocha command to
mocha --require babel-register
. More info on that here: https://babeljs.io/docs/setup#installation