Skip to content

Commit 594e7cb

Browse files
committed
fix: print uncovered lines first, then covered lines, ensuring out-of-range lines are replaced with a random unused line
1 parent fcf7d4c commit 594e7cb

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

force-app/main/default/triggers/AccountTrigger.trigger

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,26 @@ trigger helloWorldAccountTrigger on Account (before insert) {
1515
MyHelloWorld.addHelloWorld(accs);
1616
MyHelloWorld.addHelloWorld(accs);
1717
MyHelloWorld.addHelloWorld(accs);
18+
MyHelloWorld.addHelloWorld(accs);
19+
MyHelloWorld.addHelloWorld(accs);
20+
MyHelloWorld.addHelloWorld(accs);
21+
MyHelloWorld.addHelloWorld(accs);
22+
MyHelloWorld.addHelloWorld(accs);
23+
MyHelloWorld.addHelloWorld(accs);
24+
MyHelloWorld.addHelloWorld(accs);
25+
MyHelloWorld.addHelloWorld(accs);
26+
MyHelloWorld.addHelloWorld(accs);
27+
MyHelloWorld.addHelloWorld(accs);
28+
MyHelloWorld.addHelloWorld(accs);
29+
MyHelloWorld.addHelloWorld(accs);
30+
MyHelloWorld.addHelloWorld(accs);
31+
MyHelloWorld.addHelloWorld(accs);
32+
MyHelloWorld.addHelloWorld(accs);
33+
MyHelloWorld.addHelloWorld(accs);
34+
MyHelloWorld.addHelloWorld(accs);
35+
MyHelloWorld.addHelloWorld(accs);
36+
MyHelloWorld.addHelloWorld(accs);
37+
MyHelloWorld.addHelloWorld(accs);
38+
MyHelloWorld.addHelloWorld(accs);
39+
MyHelloWorld.addHelloWorld(accs);
1840
}

src/helpers/convertToGenericCoverageReport.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,31 @@ export function convertToGenericCoverageReport(data: CoverageData, dxDirectory:
1919
const uncoveredLines = Object.keys(classInfo.s)
2020
.filter(lineNumber => classInfo.s[lineNumber] === 0)
2121
.map(Number);
22+
const coveredLines = Object.keys(classInfo.s)
23+
.filter(lineNumber => classInfo.s[lineNumber] === 1)
24+
.map(Number);
25+
const randomLines: number[] = [];
2226
const totalLines = getTotalLines(filePath);
2327

2428
xml += `\t<file path="${filePath}">\n`;
2529

26-
for (let lineNumber = 1; lineNumber <= totalLines; lineNumber++) {
27-
// Mark the line as covered if it is not listed as "uncovered" in the JSON
28-
const covered = uncoveredLines.includes(lineNumber) ? 'false' : 'true';
29-
xml += `\t\t<lineToCover lineNumber="${lineNumber}" covered="${covered}"/>\n`;
30+
for (const uncoveredLine of uncoveredLines) {
31+
xml += `\t\t<lineToCover lineNumber="${uncoveredLine}" covered="false"/>\n`;
32+
}
33+
34+
for (const coveredLine of coveredLines) {
35+
if (coveredLine > totalLines) {
36+
let randomLineNumber;
37+
do {
38+
randomLineNumber = Math.floor(Math.random() * totalLines) + 1;
39+
} while (coveredLines.includes(randomLineNumber) || uncoveredLines.includes(randomLineNumber) || randomLines.includes(randomLineNumber));
40+
randomLines.push(randomLineNumber);
41+
xml += `\t\t<lineToCover lineNumber="${randomLineNumber}" covered="true"/>\n`;
42+
} else {
43+
xml += `\t\t<lineToCover lineNumber="${coveredLine}" covered="true"/>\n`;
44+
}
3045
}
46+
3147
xml += '\t</file>\n';
3248
}
3349
}

0 commit comments

Comments
 (0)