Skip to content

Commit

Permalink
fix: print uncovered lines first, then covered lines, ensuring out-of…
Browse files Browse the repository at this point in the history
…-range lines are replaced with a random unused line
  • Loading branch information
mcarvin8 committed Mar 5, 2024
1 parent fcf7d4c commit 594e7cb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
22 changes: 22 additions & 0 deletions force-app/main/default/triggers/AccountTrigger.trigger
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,26 @@ trigger helloWorldAccountTrigger on Account (before insert) {
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
MyHelloWorld.addHelloWorld(accs);
}
24 changes: 20 additions & 4 deletions src/helpers/convertToGenericCoverageReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,31 @@ export function convertToGenericCoverageReport(data: CoverageData, dxDirectory:
const uncoveredLines = Object.keys(classInfo.s)
.filter(lineNumber => classInfo.s[lineNumber] === 0)
.map(Number);
const coveredLines = Object.keys(classInfo.s)
.filter(lineNumber => classInfo.s[lineNumber] === 1)
.map(Number);
const randomLines: number[] = [];
const totalLines = getTotalLines(filePath);

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

for (let lineNumber = 1; lineNumber <= totalLines; lineNumber++) {
// Mark the line as covered if it is not listed as "uncovered" in the JSON
const covered = uncoveredLines.includes(lineNumber) ? 'false' : 'true';
xml += `\t\t<lineToCover lineNumber="${lineNumber}" covered="${covered}"/>\n`;
for (const uncoveredLine of uncoveredLines) {
xml += `\t\t<lineToCover lineNumber="${uncoveredLine}" covered="false"/>\n`;
}

for (const coveredLine of coveredLines) {
if (coveredLine > totalLines) {
let randomLineNumber;
do {
randomLineNumber = Math.floor(Math.random() * totalLines) + 1;
} while (coveredLines.includes(randomLineNumber) || uncoveredLines.includes(randomLineNumber) || randomLines.includes(randomLineNumber));
randomLines.push(randomLineNumber);
xml += `\t\t<lineToCover lineNumber="${randomLineNumber}" covered="true"/>\n`;
} else {
xml += `\t\t<lineToCover lineNumber="${coveredLine}" covered="true"/>\n`;
}
}

xml += '\t</file>\n';
}
}
Expand Down

0 comments on commit 594e7cb

Please sign in to comment.