Skip to content

Commit

Permalink
fix: remove covered line adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarvin8 committed May 1, 2024
1 parent 910c7db commit 8b5d189
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 221 deletions.
25 changes: 11 additions & 14 deletions src/helpers/convertToGenericCoverageReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { create } from 'xmlbuilder2';
import { CoverageData, CoverageObject, FileObject } from './types.js';
import { getPackageDirectories } from './getPackageDirectories.js';
import { findFilePath } from './findFilePath.js';
import { setCoveredLines } from './setCoveredLines.js';
import { normalizePathToUnix } from './normalizePathToUnix.js';

export async function convertToGenericCoverageReport(
Expand All @@ -26,23 +25,21 @@ export async function convertToGenericCoverageReport(
warnings.push(`The file name ${formattedFileName} was not found in any package directory.`);
continue;
}
const uncoveredLines = Object.keys(fileInfo.s)
.filter((lineNumber) => fileInfo.s[lineNumber] === 0)
.map(Number);
const coveredLines = Object.keys(fileInfo.s)
.filter((lineNumber) => fileInfo.s[lineNumber] === 1)
.map(Number);

const fileObj: FileObject = {
'@path': normalizePathToUnix(relativeFilePath),
lineToCover: uncoveredLines.map((lineNumber: number) => ({
'@lineNumber': lineNumber,
'@covered': 'false',
})),
lineToCover: [],
};

// this function is only needed until Salesforce fixes the API to correctly return covered lines
await setCoveredLines(coveredLines, uncoveredLines, repoRoot, relativeFilePath, fileObj);
for (const lineNumberString in fileInfo.s) {
if (!Object.hasOwn(fileInfo.s, lineNumberString)) continue;

const covered = fileInfo.s[lineNumberString] === 1 ? 'true' : 'false';
fileObj.lineToCover.push({
'@lineNumber': lineNumberString,
'@covered': covered,
});
}

filesProcessed++;
coverageObj.coverage.file.push(fileObj);
}
Expand Down
8 changes: 0 additions & 8 deletions src/helpers/getTotalLines.ts

This file was deleted.

40 changes: 0 additions & 40 deletions src/helpers/setCoveredLines.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface SfdxProject {
}

interface LineToCover {
'@lineNumber': number;
'@lineNumber': string;
'@covered': string;
}

Expand Down
72 changes: 0 additions & 72 deletions test/baselines/classes/AccountProfile.cls

This file was deleted.

40 changes: 0 additions & 40 deletions test/baselines/triggers/AccountTrigger.trigger

This file was deleted.

16 changes: 9 additions & 7 deletions test/commands/transformer/unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import { copyFile, readFile, writeFile, rm, mkdir } from 'node:fs/promises';
import { readFile, writeFile, rm, mkdir } from 'node:fs/promises';
import { strictEqual } from 'node:assert';
import { resolve } from 'node:path';

Expand All @@ -12,8 +12,10 @@ import TransformerTransform from '../../../src/commands/apex-code-coverage/trans
describe('main', () => {
const $$ = new TestContext();
let sfCommandStubs: ReturnType<typeof stubSfCommandUx>;
const baselineClassPath = resolve('test/baselines/classes/AccountProfile.cls');
const baselineTriggerPath = resolve('test/baselines/triggers/AccountTrigger.trigger');
const mockClassContent = '// Test Apex Class';
const mockTriggerContent = '// Test Apex Trigger';
const baselineClassPath = resolve('force-app/main/default/classes/AccountProfile.cls');
const baselineTriggerPath = resolve('packaged/triggers/AccountTrigger.trigger');
const coverageJsonPathNoExts = resolve('test/coverage_no_file_exts.json');
const coverageJsonPathWithExts = resolve('test/coverage_with_file_exts.json');
const baselineXmlPath = resolve('test/coverage_baseline.xml');
Expand All @@ -32,8 +34,8 @@ describe('main', () => {
before(async () => {
await mkdir('force-app/main/default/classes', { recursive: true });
await mkdir('packaged/triggers', { recursive: true });
await copyFile(baselineClassPath, 'force-app/main/default/classes/AccountProfile.cls');
await copyFile(baselineTriggerPath, 'packaged/triggers/AccountTrigger.trigger');
await writeFile(baselineClassPath, mockClassContent);
await writeFile(baselineTriggerPath, mockTriggerContent);
await writeFile(sfdxConfigFile, configJsonString);
});

Expand All @@ -46,8 +48,8 @@ describe('main', () => {
});

after(async () => {
await rm('force-app/main/default/classes/AccountProfile.cls');
await rm('packaged/triggers/AccountTrigger.trigger');
await rm(baselineClassPath);
await rm(baselineTriggerPath);
await rm('force-app', { recursive: true });
await rm('packaged', { recursive: true });
await rm(testXmlPath1);
Expand Down
78 changes: 39 additions & 39 deletions test/coverage_baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,46 @@
<file path="packaged/triggers/AccountTrigger.trigger">
<lineToCover lineNumber="52" covered="false"/>
<lineToCover lineNumber="53" covered="false"/>
<lineToCover lineNumber="54" covered="true"/>
<lineToCover lineNumber="55" covered="true"/>
<lineToCover lineNumber="56" covered="true"/>
<lineToCover lineNumber="57" covered="true"/>
<lineToCover lineNumber="58" covered="true"/>
<lineToCover lineNumber="59" covered="false"/>
<lineToCover lineNumber="60" covered="false"/>
<lineToCover lineNumber="1" covered="true"/>
<lineToCover lineNumber="2" covered="true"/>
<lineToCover lineNumber="3" covered="true"/>
<lineToCover lineNumber="4" covered="true"/>
<lineToCover lineNumber="5" covered="true"/>
<lineToCover lineNumber="6" covered="true"/>
<lineToCover lineNumber="7" covered="true"/>
<lineToCover lineNumber="8" covered="true"/>
<lineToCover lineNumber="9" covered="true"/>
<lineToCover lineNumber="10" covered="true"/>
<lineToCover lineNumber="11" covered="true"/>
<lineToCover lineNumber="12" covered="true"/>
<lineToCover lineNumber="13" covered="true"/>
<lineToCover lineNumber="14" covered="true"/>
<lineToCover lineNumber="15" covered="true"/>
<lineToCover lineNumber="16" covered="true"/>
<lineToCover lineNumber="17" covered="true"/>
<lineToCover lineNumber="18" covered="true"/>
<lineToCover lineNumber="19" covered="true"/>
<lineToCover lineNumber="20" covered="true"/>
<lineToCover lineNumber="21" covered="true"/>
<lineToCover lineNumber="22" covered="true"/>
<lineToCover lineNumber="23" covered="true"/>
<lineToCover lineNumber="24" covered="true"/>
<lineToCover lineNumber="25" covered="true"/>
<lineToCover lineNumber="26" covered="true"/>
<lineToCover lineNumber="27" covered="true"/>
<lineToCover lineNumber="61" covered="true"/>
<lineToCover lineNumber="62" covered="true"/>
<lineToCover lineNumber="63" covered="true"/>
<lineToCover lineNumber="64" covered="true"/>
<lineToCover lineNumber="65" covered="true"/>
<lineToCover lineNumber="66" covered="true"/>
<lineToCover lineNumber="67" covered="true"/>
<lineToCover lineNumber="68" covered="true"/>
<lineToCover lineNumber="69" covered="true"/>
<lineToCover lineNumber="70" covered="true"/>
<lineToCover lineNumber="71" covered="true"/>
<lineToCover lineNumber="72" covered="true"/>
<lineToCover lineNumber="73" covered="true"/>
<lineToCover lineNumber="74" covered="true"/>
<lineToCover lineNumber="75" covered="true"/>
<lineToCover lineNumber="76" covered="true"/>
<lineToCover lineNumber="77" covered="true"/>
<lineToCover lineNumber="78" covered="true"/>
<lineToCover lineNumber="79" covered="true"/>
<lineToCover lineNumber="80" covered="true"/>
<lineToCover lineNumber="81" covered="true"/>
<lineToCover lineNumber="82" covered="true"/>
</file>
<file path="force-app/main/default/classes/AccountProfile.cls">
<lineToCover lineNumber="52" covered="false"/>
<lineToCover lineNumber="53" covered="false"/>
<lineToCover lineNumber="59" covered="false"/>
<lineToCover lineNumber="60" covered="false"/>
<lineToCover lineNumber="54" covered="true"/>
<lineToCover lineNumber="55" covered="true"/>
<lineToCover lineNumber="56" covered="true"/>
<lineToCover lineNumber="57" covered="true"/>
<lineToCover lineNumber="58" covered="true"/>
<lineToCover lineNumber="59" covered="false"/>
<lineToCover lineNumber="60" covered="false"/>
<lineToCover lineNumber="61" covered="true"/>
<lineToCover lineNumber="62" covered="true"/>
<lineToCover lineNumber="63" covered="true"/>
Expand All @@ -55,15 +55,15 @@
<lineToCover lineNumber="70" covered="true"/>
<lineToCover lineNumber="71" covered="true"/>
<lineToCover lineNumber="72" covered="true"/>
<lineToCover lineNumber="1" covered="true"/>
<lineToCover lineNumber="2" covered="true"/>
<lineToCover lineNumber="3" covered="true"/>
<lineToCover lineNumber="4" covered="true"/>
<lineToCover lineNumber="5" covered="true"/>
<lineToCover lineNumber="6" covered="true"/>
<lineToCover lineNumber="7" covered="true"/>
<lineToCover lineNumber="8" covered="true"/>
<lineToCover lineNumber="9" covered="true"/>
<lineToCover lineNumber="10" covered="true"/>
<lineToCover lineNumber="73" covered="true"/>
<lineToCover lineNumber="74" covered="true"/>
<lineToCover lineNumber="75" covered="true"/>
<lineToCover lineNumber="76" covered="true"/>
<lineToCover lineNumber="77" covered="true"/>
<lineToCover lineNumber="78" covered="true"/>
<lineToCover lineNumber="79" covered="true"/>
<lineToCover lineNumber="80" covered="true"/>
<lineToCover lineNumber="81" covered="true"/>
<lineToCover lineNumber="82" covered="true"/>
</file>
</coverage>

0 comments on commit 8b5d189

Please sign in to comment.