Code coverage is 100% despite lcov.info showing less

I have a simple typescript prototype project where I’m generating an lcov.info file with nyc and then using sonarcloud-github-action to upload the results. This is what my lcov.info looks like:

TN:
SF:src/Button.tsx
FN:14,(anonymous_0)
FNF:1
FNH:1
FNDA:1,(anonymous_0)
DA:4,1
DA:14,1
DA:19,1
LF:3
LH:3
BRF:0
BRH:0
end_of_record
TN:
SF:src/List.tsx
FN:12,(anonymous_0)
FNF:1
FNH:1
FNDA:1,(anonymous_0)
DA:4,1
DA:12,1
DA:13,1
LF:3
LH:3
BRF:0
BRH:0
end_of_record
TN:
SF:src/index.tsx
FN:7,(anonymous_0)
FN:8,(anonymous_1)
FN:9,(anonymous_2)
FN:12,(anonymous_3)
FNF:4
FNH:2
FNDA:1,(anonymous_0)
FNDA:1,(anonymous_1)
FNDA:0,(anonymous_2)
FNDA:0,(anonymous_3)
DA:7,1
DA:8,1
DA:9,1
DA:12,1
DA:14,1
DA:26,1
LF:6
LH:6
BRF:0
BRH:0
end_of_record

I can see in the file that in src/index.tsx, 2 of the functions were never invoked when my tests ran, yet when sonarcloud consumes it, it shows that my coverage is 100% for for src/index.tsx. I would expect the coverage to be lower than 100%.

If I delete the file, the test coverage drops to 0%, so I know it’s being used somehow.

I’m not really sure how to debug this. Any help would be greatly appreciated.

We consider 2 types of data from lcov report: DA (line coverage) and BRDA (condition coverage).
Only lines mentioned with those prefixes are considered executable (thus impacting coverage result).
So if you know that some lines are not covered we would expect to see DA: 42, 0 in report (where 42 is uncovered line).

Double check that you generate your report in compliance with those requirements.

1 Like

Hi,
this still doesn’t explain why lcov.info showing uncovered lines although they are newly covered by tests in jest.