question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

code coverage with nyc fails to cover all paths when using rewire@3

See original GitHub issue

Expected 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:closed
  • Created 6 years ago
  • Reactions:14
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jhnnscommented, Jun 11, 2018

Can you provide a minimal reproducible example? 😃 That would help me to track down the bug.

1reaction
bforbiscommented, Apr 10, 2018

@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 to rewire@4 correctly preserves the code coverage from nyc, 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:

 "before all" hook:
     Error: global leak detected: __core-js_shared__

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found