How to get new line coverage percent in jest (not entire file %)
Asked Answered
G

0

6

I've been using jest --coverage to calculate coverage for my code. I've added a coverageThreshold in jest.config.js but this only checks whole codebase/folder coverage.

I also tried jest -o (--onlyChanged) but this generates coverage percent for the entire file making actual new line coverage seem higher than it is.

Is there any way to check jest --coverage coverage percentage on new lines only (not changed lines)??

EXAMPLE: whole file coverage example, will pass global threshold of 95%. one new if statement line, didn't write a test for:

--------------|---------|----------|---------|---------|-------------------
File          | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
--------------|---------|----------|---------|---------|-------------------
All files     |   96.15 |    95.83 |     100 |   95.83 |                   
changeFile.tsx|   96.15 |    95.83 |     100 |   95.83 | 119               
--------------|---------|----------|---------|---------|-------------------



EXAMPLE: as supposed to NEW line coverage example, will fail if global threshold is 95%, fails due to one of the lines not covered.
--------------|---------|----------|---------|---------|-------------------
File          | % Stmts | % Branch | % Funcs | % Lines | Uncovered New Line #s 
--------------|---------|----------|---------|---------|-------------------   
changeFile.tsx|   50.00 |     100  |  100    |  100    | 1/2               
--------------|---------|----------|---------|---------|-------------------

tried:

jest -o (--onlyChanged) , --lastCommit, --changedSince

but they only calculate coverage percent of entire changed file


If theres other coverage tools that can accomplish this, suggestions would be appreciated :)

Gallium answered 6/7, 2023 at 17:14 Comment(2)
Cloud you please let me know if you've located any solution?Lowrance
Not possible yet locally. ended up removing new line threshold and depending on git sourcing for reviewers to see new line coverage during cr process.Gallium

© 2022 - 2024 — McMap. All rights reserved.