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

Make test files change trigger coverage of source code under watch mode and version control #8545

Closed
chenesan opened this issue Jun 10, 2019 · 7 comments 路 Fixed by #9769
Closed

Comments

@chenesan
Copy link
Contributor

馃殌 Feature Proposal

Make test files change trigger coverage of related source code under --watch and git version control.

Motivation

Related to #7331 and #8491 (Not sure if it's related to any earlier issue before) . In some cases we may add tests in existed test files and want to see if the addes tests increase code coverage. However currently Jest only show coverage of changed files -- So even we have added / removed the test, we still cannot see the coverage change because source code is not changed, which is really a pain point when increasing coverage. Even though it's possible to set forceCoverageMatch to force jest keep an eye on specific files, it's still not so easy to use it when you're not 100% sure how many files you'd like to watch.

So I propose jest should automatically track the coverage of source files that are tested by changed test files, even though it's unchanged and under vcs + watch mode.

Example

Assume you have a source file a.js and a test file test.js for a.js. When test.js changes under watch mode and vcs (or -o), jest cli should show the coverage of a.js.

@chenesan
Copy link
Contributor Author

By the way, I'd love to help with this but I'm not sure where to start. In my imagination we can fix with following steps:

  1. get all the test files and their dependency graph of source files.
  2. if any test file changes, we can add the related source files into a set.
  3. in shouldInstrument if the file is in the set in (2) then we will instrument it even it's not in changedFiles.

But I don't know how each part is handled (or not handled) in Jest. I may try to look into this in a few day. @jeysal could you guide me where the corresponding code is around the steps? Or do you have any other idea?

@jeysal
Copy link
Contributor

jeysal commented Jun 11, 2019

@chenesan Would love to accept a contribution on this!
I don't have a very concrete idea on how to go about this yet, but we should definitely have most of the needed dependency graph utils in place already :)
Maybe you could look at #5601 to find the relevant places, that does something very similar.
Actually, shouldn't that PR have implemented this already or am I reading it wrong? @SimenB since you were around since then, did this actually work previously and this is a bug?

@chenesan
Copy link
Contributor Author

Thanks for guidance @jeysal . I'll look into #5601 and try to seek a way to build / fix this :-) @SimenB Is this a bug or a new feature?

@chenesan
Copy link
Contributor Author

chenesan commented Apr 3, 2020

Hi @jeysal , is it still good to work on this? I'd like to be back to work on this 馃敤

@jeysal
Copy link
Contributor

jeysal commented Apr 3, 2020

Yes, afaik nothing changed regarding this. Just out of curiosity @SimenB do you know if this used to work? (see above) It seems like the obvious behavior.

@SimenB
Copy link
Member

SimenB commented Apr 3, 2020

I think it worked yeah, but I'm not 100% sure.

@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 May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants