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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with coverage and rewire #8871

Closed
tandros-div opened this issue Aug 23, 2019 · 14 comments
Closed

Issues with coverage and rewire #8871

tandros-div opened this issue Aug 23, 2019 · 14 comments

Comments

@tandros-div
Copy link

tandros-div commented Aug 23, 2019

馃悰 Bug Report

Hi,
I have a public repo that doesn't produce coverage for file scraper.test.js. File is found in tests directory. I do have another test file that doesn't have any issue.

However, the problematic file is using rewire npm module, and I have seen some issues with it lately. I did try to completely remove it, but the problem still persists.

To Reproduce

In folder crawler
Run:
jest --coverage --bail --findRelatedTests ./__tests__/scraper.test.js
or:
jest --coverage

Expected behavior

I expect to see coverage report for scraper.js.
Tests run successfully but I there is no coverage data.

Link to repl or repo

Repo - develop branch

envinfo

System:
OS: Linux 5.2 Fedora 30 (Workstation Edition) 30 (Workstation Edition)
CPU: (4) x64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
Binaries:
Node: 12.8.1 - /usr/bin/node
npm: 6.11.2 - ~/.npm-packages/bin/npm
npmPackages:
jest: ^24.9.0 => 24.9.0

@thymikee
Copy link
Collaborator

Please provide some instructions in the repro on what's the issue and how to achieve it

@An-dz
Copy link

An-dz commented Sep 25, 2019

Just try loading a module with rewire instead of require and jest will not calculate coverage of this file.

@JNBourrat
Copy link

@tandros-div Hi! I'm running into the same issue unfortunately: jest --coverage does not seem to take into account my rewired modules. Did you find a way to report you actual test coverage?

@SimenB
Copy link
Member

SimenB commented Jan 14, 2020

I doubt we'll add support for rewire (jest has builtin support for mocking modules via jest.mock and jest.doMock), but if anybody wanna send a PR that's of course welcome

@SimenB SimenB changed the title Issues with coverage Issues with coverage and rewire Jan 14, 2020
@An-dz
Copy link

An-dz commented Jan 16, 2020

@JNBourrat I decided to go with AVA. I ended up really liking the way it works and its syntax, including that not writing an assert fails the test.

@JNBourrat
Copy link

@An-dz Thanks, I'll be sure to take a look at it.

For my end I ended up using babel-plugin-rewire instead of rewire itself. I was able to use __get__ and __set__ to mock the tested module's private functions and not rewire the whole module.

@An-dz
Copy link

An-dz commented Jan 18, 2020

@JNBourrat I thought about using babel-rewire but it has many dependencies and I wanted to keep my project slim.

@SimenB nyc/istanbul had a similar bug I helped to track down, whenever you guy wish to try to fix this these are the issues:
istanbuljs/nyc#1169
istanbuljs/nyc#1029

@cqcmdwym
Copy link

Found a temp solution: https://www.grzegorowski.com/jest-tests-with-rewire-plugin
We can use babel-jest and babel-plugin-rewire

@ryancabanas
Copy link

Found a temp solution: https://www.grzegorowski.com/jest-tests-with-rewire-plugin We can use babel-jest and babel-plugin-rewire

@cqcmdwym I followed the simple instructions that you linked, but I can't get babel-plugin-rewire to work. I keep getting the message TypeError: Cannot read property '__Rewire__' of undefined when I try to use it. :( You didn't happen to run into any additional configuration steps that needed to be done to get this to work with Jest unit tests, did you? Thanks so much for the help!

@cqcmdwym
Copy link

Found a temp solution: https://www.grzegorowski.com/jest-tests-with-rewire-plugin We can use babel-jest and babel-plugin-rewire

@cqcmdwym I followed the simple instructions that you linked, but I can't get babel-plugin-rewire to work. I keep getting the message TypeError: Cannot read property '__Rewire__' of undefined when I try to use it. :( You didn't happen to run into any additional configuration steps that needed to be done to get this to work with Jest unit tests, did you? Thanks so much for the help!

Looks like you haven't configed babel in babel config file?

@SergioSuarezDev
Copy link

Hi guys, i'm trying to use babel-jest and babel-plugin-rewire

but i have these errors (a lot of them)

Property property of OptionalMemberExpression expected node to be of a type ["Identifier"] but instead got "CallExpression"

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label May 10, 2023
@github-actions
Copy link

github-actions bot commented Jun 9, 2023

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 9, 2023
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants