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 Oct 21, 2024
1 parent 3d2f426 commit 14a6c54
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 228 deletions.
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.

23 changes: 10 additions & 13 deletions src/helpers/transformDeployCoverageReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { create } from 'xmlbuilder2';
import { DeployCoverageData, 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 transformDeployCoverageReport(
Expand All @@ -26,23 +25,21 @@ export async function transformDeployCoverageReport(
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': Number(lineNumberString),
'@covered': covered,
});
}

filesProcessed++;
coverageObj.coverage.file.push(fileObj);
}
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.

21 changes: 12 additions & 9 deletions test/commands/acc-transformer/transform.nut.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

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

Expand All @@ -9,15 +9,18 @@ import { expect } from 'chai';

describe('acc-transformer transform NUTs', () => {
let session: TestSession;
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 deployCoverageNoExts = resolve('test/deploy_coverage_no_file_exts.json');
const deployCoverageWithExts = resolve('test/deploy_coverage_with_file_exts.json');
const testCoverage = resolve('test/test_coverage.json');
const baselineXmlPath = resolve('test/coverage_baseline.xml');
const testXmlPath1 = resolve('coverage1.xml');
const testXmlPath2 = resolve('coverage2.xml');
const testXmlPath3 = resolve('coverage3.xml');
const sfdxConfigFile = resolve('sfdx-project.json');

const configFile = {
packageDirectories: [{ path: 'force-app', default: true }, { path: 'packaged' }],
Expand All @@ -29,18 +32,18 @@ describe('acc-transformer transform NUTs', () => {

before(async () => {
session = await TestSession.create({ devhubAuthStrategy: 'NONE' });
await writeFile('sfdx-project.json', configJsonString);
await writeFile(sfdxConfigFile, configJsonString);
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);
});

after(async () => {
await session?.clean();
await rm('sfdx-project.json');
await rm('force-app/main/default/classes/AccountProfile.cls');
await rm('packaged/triggers/AccountTrigger.trigger');
await rm(sfdxConfigFile);
await rm(baselineClassPath);
await rm(baselineTriggerPath);
await rm('force-app', { recursive: true });
await rm('packaged', { recursive: true });
await rm(testXmlPath1);
Expand Down
16 changes: 9 additions & 7 deletions test/commands/acc-transformer/transform.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/acc-transformer/transfor
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 deployCoverageNoExts = resolve('test/deploy_coverage_no_file_exts.json');
const deployCoverageWithExts = resolve('test/deploy_coverage_with_file_exts.json');
const testCoverage = resolve('test/test_coverage.json');
Expand All @@ -34,8 +36,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 @@ -48,8 +50,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
Loading

0 comments on commit 14a6c54

Please sign in to comment.