@@ -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 ;
@@ -159,12 +163,20 @@ class TestCoverage {
159
163
for ( let j = 0 ; j < functions . length ; ++ j ) {
160
164
const { isBlockCoverage, ranges } = functions [ j ] ;
161
165
166
+ let maxCountPerFunction = 0 ;
162
167
for ( let k = 0 ; k < ranges . length ; ++ k ) {
163
168
const range = ranges [ k ] ;
169
+ maxCountPerFunction = MathMax ( maxCountPerFunction , range . count ) ;
164
170
165
171
mapRangeToLines ( range , lines ) ;
166
172
167
173
if ( isBlockCoverage ) {
174
+ ArrayPrototypePush ( branchReports , {
175
+ __proto__ : null ,
176
+ line : range . lines [ 0 ] . line ,
177
+ count : range . count ,
178
+ } ) ;
179
+
168
180
if ( range . count !== 0 ||
169
181
range . ignoredLines === range . lines . length ) {
170
182
branchesCovered ++ ;
@@ -177,6 +189,13 @@ class TestCoverage {
177
189
if ( j > 0 && ranges . length > 0 ) {
178
190
const range = ranges [ 0 ] ;
179
191
192
+ ArrayPrototypePush ( functionReports , {
193
+ __proto__ : null ,
194
+ name : functions [ j ] . functionName ,
195
+ count : maxCountPerFunction ,
196
+ line : range . lines [ 0 ] . line ,
197
+ } ) ;
198
+
180
199
if ( range . count !== 0 || range . ignoredLines === range . lines . length ) {
181
200
functionsCovered ++ ;
182
201
}
@@ -186,15 +205,19 @@ class TestCoverage {
186
205
}
187
206
188
207
let coveredCnt = 0 ;
189
- const uncoveredLineNums = [ ] ;
208
+ const lineReports = [ ] ;
190
209
191
210
for ( let j = 0 ; j < lines . length ; ++ j ) {
192
211
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
+ }
194
219
if ( line . covered || line . ignore ) {
195
220
coveredCnt ++ ;
196
- } else {
197
- ArrayPrototypePush ( uncoveredLineNums , line . line ) ;
198
221
}
199
222
}
200
223
@@ -210,7 +233,9 @@ class TestCoverage {
210
233
coveredLinePercent : toPercentage ( coveredCnt , lines . length ) ,
211
234
coveredBranchPercent : toPercentage ( branchesCovered , totalBranches ) ,
212
235
coveredFunctionPercent : toPercentage ( functionsCovered , totalFunctions ) ,
213
- uncoveredLineNumbers : uncoveredLineNums ,
236
+ functions : functionReports ,
237
+ branches : branchReports ,
238
+ lines : lineReports ,
214
239
} ) ;
215
240
216
241
coverageSummary . totals . totalLineCount += lines . length ;
@@ -320,6 +345,11 @@ function mapRangeToLines(range, lines) {
320
345
if ( count === 0 && startOffset <= line . startOffset &&
321
346
endOffset >= line . endOffset ) {
322
347
line . covered = false ;
348
+ line . count = 0 ;
349
+ }
350
+ if ( count > 0 && startOffset <= line . startOffset &&
351
+ endOffset >= line . endOffset ) {
352
+ line . count = count ;
323
353
}
324
354
325
355
ArrayPrototypePush ( mappedLines , line ) ;
0 commit comments