Code coverage incorrectly reports 100% coverage when importing module with rewire
- Dominant language
- JavaScript
- Stars
- 2.1k
- Forks
- 99
- PR merge metrics
- No merged PRs in 30d
Description
* **Version**: v16.14.2
* **Platform**: Linux 5.15.0-46-generic
Libraries:
* **AVA** 5.0.1
* **rewire** 6.0.0
* **c8** 7.12.0
There seems to be a problem with the code coverage reported by c8 when the module under test is imported using rewire.
Rewire wraps the module with setters and getters so that private variables and functions can be stubbed.
I'm using AVA as the test runner.
My test file have no tests, I'm only importing AVA, rewire and my module:
```
test = require('ava')
rewire = require('rewire')
myModule = rewire('../lib/myModule')
```
Invoking `c8 ava` yields 100% coverage on the module.
If I simply `require()` the module instead, I get 10% or so (which is expected since the module does some initialization).
Swapping `c8` by `nyc` yields the expected 10% coverage when using rewire, so it seems the instrumentation inside rewire messes up c8's.
I struggled to find anything related to this incompatibility. Are there any other reports on this issue?
Contributor guide
Assessment
This issue has not been assessed yet.