Skip to content
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

Code coverage incorrectly reports 100% coverage when importing module with rewire #426

Open
freebeans opened this issue Nov 10, 2022 · 3 comments
Labels

Comments

@freebeans
Copy link

  • 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?

@freebeans
Copy link
Author

Feel free to edit the post or the title for clarification. I'm not a native speaker.

@jakebailey
Copy link
Contributor

jakebailey commented Nov 11, 2022

See also #34, #325. I ended up converting my entire codebase to explicitly pass in dependencies I wanted to mock and giving up on things like rewire, esmock for this reason; they just don't work with c8.

@freebeans
Copy link
Author

Is it worth it though? I'd rather keep the module code untouched.

I'm new to test driven development and I don't use any specific features from c8, so I'll be using nyc this time.

I'm affraid this might be my fault since I can't find many issues related. #34 feels like it might be related, but it's 4 years old now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants