Jest: Make test files change trigger coverage of source code under watch mode and version control

Created on 10 Jun 2019  路  6Comments  路  Source: facebook/jest

馃殌 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.

Feature Request Help Wanted

All 6 comments

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?

@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 https://github.com/facebook/jest/pull/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?

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?

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

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.

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

Was this page helpful?
0 / 5 - 0 ratings