@@ -13,6 +13,7 @@ const {
1313 StringPrototypeIncludes,
1414 StringPrototypeLocaleCompare,
1515 StringPrototypeStartsWith,
16+ MathMax,
1617} = primordials ;
1718const {
1819 copyFileSync,
@@ -43,6 +44,7 @@ class CoverageLine {
4344 this . startOffset = startOffset ;
4445 this . endOffset = startOffset + src . length - newlineLength ;
4546 this . ignore = false ;
47+ this . count = 0 ;
4648 this . #covered = true ;
4749 }
4850
@@ -118,6 +120,8 @@ class TestCoverage {
118120 let totalFunctions = 0 ;
119121 let branchesCovered = 0 ;
120122 let functionsCovered = 0 ;
123+ const functionReports = [ ] ;
124+ const branchReports = [ ] ;
121125
122126 const lines = ArrayPrototypeMap ( linesWithBreaks , ( line , i ) => {
123127 const startOffset = offset ;
@@ -159,12 +163,20 @@ class TestCoverage {
159163 for ( let j = 0 ; j < functions . length ; ++ j ) {
160164 const { isBlockCoverage, ranges } = functions [ j ] ;
161165
166+ let maxCountPerFunction = 0 ;
162167 for ( let k = 0 ; k < ranges . length ; ++ k ) {
163168 const range = ranges [ k ] ;
169+ maxCountPerFunction = MathMax ( maxCountPerFunction , range . count ) ;
164170
165171 mapRangeToLines ( range , lines ) ;
166172
167173 if ( isBlockCoverage ) {
174+ ArrayPrototypePush ( branchReports , {
175+ __proto__ : null ,
176+ line : range . lines [ 0 ] . line ,
177+ count : range . count ,
178+ } ) ;
179+
168180 if ( range . count !== 0 ||
169181 range . ignoredLines === range . lines . length ) {
170182 branchesCovered ++ ;
@@ -177,6 +189,13 @@ class TestCoverage {
177189 if ( j > 0 && ranges . length > 0 ) {
178190 const range = ranges [ 0 ] ;
179191
192+ ArrayPrototypePush ( functionReports , {
193+ __proto__ : null ,
194+ name : functions [ j ] . functionName ,
195+ count : maxCountPerFunction ,
196+ line : range . lines [ 0 ] . line ,
197+ } ) ;
198+
180199 if ( range . count !== 0 || range . ignoredLines === range . lines . length ) {
181200 functionsCovered ++ ;
182201 }
@@ -186,15 +205,19 @@ class TestCoverage {
186205 }
187206
188207 let coveredCnt = 0 ;
189- const uncoveredLineNums = [ ] ;
208+ const lineReports = [ ] ;
190209
191210 for ( let j = 0 ; j < lines . length ; ++ j ) {
192211 const line = lines [ j ] ;
193-
212+ if ( ! line . ignore ) {
213+ ArrayPrototypePush ( lineReports , {
214+ __proto__ : null ,
215+ line : line . line ,
216+ count : line . count ,
217+ } ) ;
218+ }
194219 if ( line . covered || line . ignore ) {
195220 coveredCnt ++ ;
196- } else {
197- ArrayPrototypePush ( uncoveredLineNums , line . line ) ;
198221 }
199222 }
200223
@@ -210,7 +233,9 @@ class TestCoverage {
210233 coveredLinePercent : toPercentage ( coveredCnt , lines . length ) ,
211234 coveredBranchPercent : toPercentage ( branchesCovered , totalBranches ) ,
212235 coveredFunctionPercent : toPercentage ( functionsCovered , totalFunctions ) ,
213- uncoveredLineNumbers : uncoveredLineNums ,
236+ functions : functionReports ,
237+ branches : branchReports ,
238+ lines : lineReports ,
214239 } ) ;
215240
216241 coverageSummary . totals . totalLineCount += lines . length ;
@@ -320,6 +345,11 @@ function mapRangeToLines(range, lines) {
320345 if ( count === 0 && startOffset <= line . startOffset &&
321346 endOffset >= line . endOffset ) {
322347 line . covered = false ;
348+ line . count = 0 ;
349+ }
350+ if ( count > 0 && startOffset <= line . startOffset &&
351+ endOffset >= line . endOffset ) {
352+ line . count = count ;
323353 }
324354
325355 ArrayPrototypePush ( mappedLines , line ) ;
0 commit comments