jest icon indicating copy to clipboard operation
jest copied to clipboard

[Feature]: Isolated coverage reports

Open CreativeTechGuy opened this issue 2 years ago • 56 comments
trafficstars

🚀 Feature Proposal

An easy way to run Jest but generate coverage separately for each test file.

Motivation

A common pattern is to have a test file for each source file. But coverage is generated for the whole repo so one test can "accidentally" cover lines in another file. This leads to a problem where when for tests that need to be written based on code coverage, it shows that a branch is tested, but it may have been executed as a result of a different test suite that doesn't actually assert on the branch in question.

Example

Two parts:

  • An option to generate multiple coverage reports for a single Jest run (eg: one coverage report per test file)
  • The ability to define collectCoverageFrom as a function which is passed the current test file as an argument so you can dynamically set which source files coverage can be collected from given the test that is running.

Pitch

There's not an easy or efficient way to do this without it being built-in.

Currently the best/only way to do it is with a custom script that finds all test files, finds the associated source files for each test file (in our case that is based on the file name) and then run jest to test only a single test file and gather coverage from only the one source file. Then run Jest hundreds of times, one for each test file to generate coverage separately for each.

I don't believe this is a change to the default reporter rather a different way of triggering the reporter. The way that the reporters work would stay the same, it'd just be executed anew for each test file.

CreativeTechGuy avatar Feb 08 '23 21:02 CreativeTechGuy

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

github-actions[bot] avatar Mar 10 '23 21:03 github-actions[bot]

Not stale

CreativeTechGuy avatar Mar 10 '23 21:03 CreativeTechGuy

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

github-actions[bot] avatar Apr 09 '23 22:04 github-actions[bot]

Still not stale

CreativeTechGuy avatar Apr 10 '23 20:04 CreativeTechGuy

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

github-actions[bot] avatar May 10 '23 21:05 github-actions[bot]

Not stale

CreativeTechGuy avatar May 11 '23 04:05 CreativeTechGuy

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

github-actions[bot] avatar Jun 10 '23 05:06 github-actions[bot]

Not stale

CreativeTechGuy avatar Jun 11 '23 17:06 CreativeTechGuy

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

github-actions[bot] avatar Jul 11 '23 18:07 github-actions[bot]

Not stale

CreativeTechGuy avatar Jul 16 '23 02:07 CreativeTechGuy

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

github-actions[bot] avatar Aug 15 '23 03:08 github-actions[bot]

Still not stale

CreativeTechGuy avatar Aug 15 '23 19:08 CreativeTechGuy

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

github-actions[bot] avatar Sep 14 '23 19:09 github-actions[bot]

Not stale

CreativeTechGuy avatar Sep 14 '23 20:09 CreativeTechGuy

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

github-actions[bot] avatar Oct 14 '23 21:10 github-actions[bot]

Not stale

CreativeTechGuy avatar Oct 15 '23 20:10 CreativeTechGuy

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

github-actions[bot] avatar Nov 14 '23 21:11 github-actions[bot]

Not stale

CreativeTechGuy avatar Nov 14 '23 22:11 CreativeTechGuy

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

github-actions[bot] avatar Dec 14 '23 23:12 github-actions[bot]

Not stale (Happy holidays)

CreativeTechGuy avatar Dec 14 '23 23:12 CreativeTechGuy

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

github-actions[bot] avatar Jan 14 '24 00:01 github-actions[bot]

Not stale (Happy new year)

CreativeTechGuy avatar Jan 19 '24 05:01 CreativeTechGuy

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

github-actions[bot] avatar Feb 18 '24 05:02 github-actions[bot]

Not stale

CreativeTechGuy avatar Feb 19 '24 00:02 CreativeTechGuy

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

github-actions[bot] avatar Mar 20 '24 02:03 github-actions[bot]

Not stale

CreativeTechGuy avatar Mar 20 '24 18:03 CreativeTechGuy

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

github-actions[bot] avatar Apr 19 '24 19:04 github-actions[bot]

Not stale

CreativeTechGuy avatar Apr 20 '24 01:04 CreativeTechGuy

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

github-actions[bot] avatar May 20 '24 02:05 github-actions[bot]

Not stale

CreativeTechGuy avatar May 20 '24 02:05 CreativeTechGuy