@@ -2,23 +2,26 @@ import { LCOVRecord } from 'parse-lcov';
22import { AuditOutput , Issue } from '@code-pushup/models' ;
33import { toNumberPrecision , toOrdinal } from '@code-pushup/utils' ;
44import { CoverageType } from '../../config' ;
5+ import { INVALID_FUNCTION_NAME } from '../constants' ;
56import { LCOVStat } from './types' ;
67import { calculateCoverage , mergeConsecutiveNumbers } from './utils' ;
78
89export function lcovReportToFunctionStat ( record : LCOVRecord ) : LCOVStat {
10+ const validRecord = removeEmptyReport ( record ) ;
11+
912 return {
10- totalFound : record . functions . found ,
11- totalHit : record . functions . hit ,
13+ totalFound : validRecord . functions . found ,
14+ totalHit : validRecord . functions . hit ,
1215 issues :
13- record . functions . hit < record . functions . found
14- ? record . functions . details
16+ validRecord . functions . hit < validRecord . functions . found
17+ ? validRecord . functions . details
1518 . filter ( detail => ! detail . hit )
1619 . map (
1720 ( detail ) : Issue => ( {
1821 message : `Function ${ detail . name } is not called in any test case.` ,
1922 severity : 'error' ,
2023 source : {
21- file : record . file ,
24+ file : validRecord . file ,
2225 position : { startLine : detail . line } ,
2326 } ,
2427 } ) ,
@@ -27,6 +30,28 @@ export function lcovReportToFunctionStat(record: LCOVRecord): LCOVStat {
2730 } ;
2831}
2932
33+ function removeEmptyReport ( record : LCOVRecord ) : LCOVRecord {
34+ const validFunctions = record . functions . details . filter (
35+ detail => detail . name !== INVALID_FUNCTION_NAME ,
36+ ) ;
37+
38+ if ( validFunctions . length === record . functions . found ) {
39+ return record ;
40+ }
41+
42+ return {
43+ ...record ,
44+ functions : {
45+ details : validFunctions ,
46+ found : validFunctions . length ,
47+ hit : validFunctions . reduce (
48+ ( acc , fn ) => acc + ( fn . hit != null && fn . hit > 0 ? 1 : 0 ) ,
49+ 0 ,
50+ ) ,
51+ } ,
52+ } ;
53+ }
54+
3055export function lcovReportToLineStat ( record : LCOVRecord ) : LCOVStat {
3156 const missingCoverage = record . lines . hit < record . lines . found ;
3257 const lines = missingCoverage
0 commit comments