@@ -13,6 +13,7 @@ const {
13
13
StringPrototypeIncludes,
14
14
StringPrototypeLocaleCompare,
15
15
StringPrototypeStartsWith,
16
+ MathMax
16
17
} = primordials ;
17
18
const {
18
19
copyFileSync,
@@ -43,6 +44,7 @@ class CoverageLine {
43
44
this . startOffset = startOffset ;
44
45
this . endOffset = startOffset + src . length - newlineLength ;
45
46
this . ignore = false ;
47
+ this . count = 0 ;
46
48
this . #covered = true ;
47
49
}
48
50
@@ -118,6 +120,8 @@ class TestCoverage {
118
120
let totalFunctions = 0 ;
119
121
let branchesCovered = 0 ;
120
122
let functionsCovered = 0 ;
123
+ const functionReports = [ ] ;
124
+ const branchReports = [ ] ;
121
125
122
126
const lines = ArrayPrototypeMap ( linesWithBreaks , ( line , i ) => {
123
127
const startOffset = offset ;
@@ -165,6 +169,11 @@ class TestCoverage {
165
169
mapRangeToLines ( range , lines ) ;
166
170
167
171
if ( isBlockCoverage ) {
172
+ ArrayPrototypePush ( branchReports , {
173
+ line : range . lines [ 0 ] . line ,
174
+ count : range . count
175
+ } ) ;
176
+
168
177
if ( range . count !== 0 ||
169
178
range . ignoredLines === range . lines . length ) {
170
179
branchesCovered ++ ;
@@ -177,6 +186,12 @@ class TestCoverage {
177
186
if ( j > 0 && ranges . length > 0 ) {
178
187
const range = ranges [ 0 ] ;
179
188
189
+ ArrayPrototypePush ( functionReports , {
190
+ name : functions [ j ] . functionName ,
191
+ count : MathMax ( ...ArrayPrototypeMap ( ranges , r => r . count ) ) ,
192
+ line : range . lines [ 0 ] . line
193
+ } ) ;
194
+
180
195
if ( range . count !== 0 || range . ignoredLines === range . lines . length ) {
181
196
functionsCovered ++ ;
182
197
}
@@ -186,15 +201,18 @@ class TestCoverage {
186
201
}
187
202
188
203
let coveredCnt = 0 ;
189
- const uncoveredLineNums = [ ] ;
204
+ const lineReports = [ ] ;
190
205
191
206
for ( let j = 0 ; j < lines . length ; ++ j ) {
192
207
const line = lines [ j ] ;
193
208
194
209
if ( line . covered || line . ignore ) {
195
210
coveredCnt ++ ;
211
+ if ( ! line . ignore ) {
212
+ ArrayPrototypePush ( lineReports , { line : line . line , count : line . count } )
213
+ }
196
214
} else {
197
- ArrayPrototypePush ( uncoveredLineNums , line . line ) ;
215
+ ArrayPrototypePush ( lineReports , { line : line . line , count : 0 } ) ;
198
216
}
199
217
}
200
218
@@ -210,7 +228,9 @@ class TestCoverage {
210
228
coveredLinePercent : toPercentage ( coveredCnt , lines . length ) ,
211
229
coveredBranchPercent : toPercentage ( branchesCovered , totalBranches ) ,
212
230
coveredFunctionPercent : toPercentage ( functionsCovered , totalFunctions ) ,
213
- uncoveredLineNumbers : uncoveredLineNums ,
231
+ functions : functionReports ,
232
+ branches : branchReports ,
233
+ lines : lineReports ,
214
234
} ) ;
215
235
216
236
coverageSummary . totals . totalLineCount += lines . length ;
@@ -321,6 +341,10 @@ function mapRangeToLines(range, lines) {
321
341
endOffset >= line . endOffset ) {
322
342
line . covered = false ;
323
343
}
344
+ if ( count > 0 && startOffset <= line . startOffset &&
345
+ endOffset >= line . endOffset ) {
346
+ line . count = count ;
347
+ }
324
348
325
349
ArrayPrototypePush ( mappedLines , line ) ;
326
350
0 commit comments