@@ -17,11 +17,11 @@ export function convertToGenericCoverageReport(data: CoverageData, dxDirectory:
17
17
}
18
18
// Extract the "uncovered lines" from the JSON data
19
19
const uncoveredLines = Object . keys ( classInfo . s )
20
- . filter ( lineNumber => classInfo . s [ lineNumber ] === 0 )
21
- . map ( Number ) ;
20
+ . filter ( lineNumber => classInfo . s [ lineNumber ] === 0 )
21
+ . map ( Number ) ;
22
22
const coveredLines = Object . keys ( classInfo . s )
23
- . filter ( lineNumber => classInfo . s [ lineNumber ] === 1 )
24
- . map ( Number ) ;
23
+ . filter ( lineNumber => classInfo . s [ lineNumber ] === 1 )
24
+ . map ( Number ) ;
25
25
const randomLines : number [ ] = [ ] ;
26
26
const totalLines = getTotalLines ( filePath ) ;
27
27
@@ -30,21 +30,25 @@ export function convertToGenericCoverageReport(data: CoverageData, dxDirectory:
30
30
for ( const uncoveredLine of uncoveredLines ) {
31
31
xml += `\t\t<lineToCover lineNumber="${ uncoveredLine } " covered="false"/>\n` ;
32
32
}
33
+ let totalCoveredLinesInXML = 0 ;
33
34
34
35
for ( const coveredLine of coveredLines ) {
35
36
if ( coveredLine > totalLines ) {
36
37
for ( let randomLineNumber = 1 ; randomLineNumber <= totalLines ; randomLineNumber ++ ) {
37
38
if (
38
39
! uncoveredLines . includes ( randomLineNumber ) &&
39
40
! coveredLines . includes ( randomLineNumber ) &&
40
- ! randomLines . includes ( randomLineNumber )
41
+ ! randomLines . includes ( randomLineNumber ) &&
42
+ totalCoveredLinesInXML < coveredLines . length
41
43
) {
42
44
xml += `\t\t<lineToCover lineNumber="${ randomLineNumber } " covered="true"/>\n` ;
43
45
randomLines . push ( randomLineNumber ) ;
46
+ totalCoveredLinesInXML ++ ;
44
47
}
45
48
}
46
49
} else {
47
50
xml += `\t\t<lineToCover lineNumber="${ coveredLine } " covered="true"/>\n` ;
51
+ totalCoveredLinesInXML ++ ;
48
52
}
49
53
}
50
54
@@ -55,6 +59,7 @@ export function convertToGenericCoverageReport(data: CoverageData, dxDirectory:
55
59
return xml ;
56
60
}
57
61
62
+
58
63
function getTotalLines ( filePath : string ) : number {
59
64
const fileContent = fs . readFileSync ( filePath , 'utf8' ) ;
60
65
return fileContent . split ( / \r \n | \r | \n / ) . length ;
0 commit comments