From 594e7cb47b6acf0823a02fb67a3cc681980e8e0f Mon Sep 17 00:00:00 2001 From: Matt Carvin <90224411+mcarvin8@users.noreply.github.com> Date: Tue, 5 Mar 2024 18:33:33 -0500 Subject: [PATCH] fix: print uncovered lines first, then covered lines, ensuring out-of-range lines are replaced with a random unused line --- .../default/triggers/AccountTrigger.trigger | 22 +++++++++++++++++ src/helpers/convertToGenericCoverageReport.ts | 24 +++++++++++++++---- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/force-app/main/default/triggers/AccountTrigger.trigger b/force-app/main/default/triggers/AccountTrigger.trigger index a73a94f..cd99f1a 100644 --- a/force-app/main/default/triggers/AccountTrigger.trigger +++ b/force-app/main/default/triggers/AccountTrigger.trigger @@ -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); } diff --git a/src/helpers/convertToGenericCoverageReport.ts b/src/helpers/convertToGenericCoverageReport.ts index 0b34c3d..ab2604e 100644 --- a/src/helpers/convertToGenericCoverageReport.ts +++ b/src/helpers/convertToGenericCoverageReport.ts @@ -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\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\n`; + for (const uncoveredLine of uncoveredLines) { + xml += `\t\t\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\n`; + } else { + xml += `\t\t\n`; + } } + xml += '\t\n'; } }