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