Skip to content

Commit 64c15a5

Browse files
authored
test: run all formats in 1 command (#197)
1 parent b189300 commit 64c15a5

File tree

4 files changed

+21
-29
lines changed

4 files changed

+21
-29
lines changed

test/commands/acc-transformer/transform.nut.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
/* eslint-disable no-await-in-loop */
21
'use strict';
32

4-
import { resolve } from 'node:path';
53
import { describe, it, expect } from '@jest/globals';
64

75
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
@@ -14,6 +12,7 @@ import { preTestSetup } from '../../utils/testSetup.js';
1412

1513
describe('acc-transformer transform NUTs', () => {
1614
let session: TestSession;
15+
const formatString = formatOptions.map((f) => `--format ${f}`).join(' ');
1716

1817
beforeAll(async () => {
1918
session = await TestSession.create({ devhubAuthStrategy: 'NONE' });
@@ -25,16 +24,21 @@ describe('acc-transformer transform NUTs', () => {
2524
await postTestCleanup();
2625
});
2726

28-
formatOptions.forEach((format) => {
29-
inputJsons.forEach(({ label, path }) => {
30-
const reportExtension = getExtensionForFormat(format);
31-
const reportPath = resolve(`${format}_${label}${reportExtension}`);
32-
it(`transforms the ${label} command JSON file into ${format} format`, async () => {
33-
const command = `acc-transformer transform --coverage-json "${path}" --output-report "${reportPath}" --format ${format} -i "samples"`;
34-
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;
35-
36-
expect(output.replace('\n', '')).toStrictEqual(`The coverage report has been written to: ${reportPath}`);
37-
});
27+
inputJsons.forEach(({ label, path }) => {
28+
it(`transforms the ${label} command JSON file into all formats`, async () => {
29+
const command = `acc-transformer transform --coverage-json "${path}" --output-report "${label}.xml" ${formatString} -i "samples"`;
30+
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;
31+
32+
const expectedOutput =
33+
'The coverage report has been written to: ' +
34+
formatOptions
35+
.map((f) => {
36+
const ext = getExtensionForFormat(f);
37+
return `${label}-${f}${ext}`;
38+
})
39+
.join(', ');
40+
41+
expect(output.replace('\n', '')).toStrictEqual(expectedOutput);
3842
});
3943
});
4044

test/commands/acc-transformer/transform.test.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
/* eslint-disable no-await-in-loop */
21
'use strict';
3-
import { resolve } from 'node:path';
4-
import { rm } from 'node:fs/promises';
52
import { describe, it, expect } from '@jest/globals';
63

74
import { TestContext } from '@salesforce/core/testSetup';
@@ -25,17 +22,11 @@ describe('acc-transformer transform unit tests', () => {
2522

2623
afterAll(async () => {
2724
await postTestCleanup();
28-
await rm('coverage-cobertura.xml');
29-
await rm('coverage-sonar.xml');
3025
});
3126

32-
formatOptions.forEach((format) => {
33-
inputJsons.forEach(({ label, path }) => {
34-
const reportExtension = format === 'lcovonly' ? 'info' : 'xml';
35-
const reportPath = resolve(`${format}_${label}.${reportExtension}`);
36-
it(`transforms the ${label} command JSON file into ${format} format`, async () => {
37-
await transformCoverageReport(path, reportPath, [format], ['samples']);
38-
});
27+
inputJsons.forEach(({ label, path }) => {
28+
it(`transforms the ${label} command JSON file into all output formats`, async () => {
29+
await transformCoverageReport(path, `${label}.xml`, formatOptions, ['samples']);
3930
});
4031
});
4132
it('confirm the reports created are the same as the baselines.', async () => {
@@ -78,7 +69,4 @@ describe('acc-transformer transform unit tests', () => {
7869
it('create a jacoco report using only 1 package directory', async () => {
7970
await transformCoverageReport(deployCoverage, 'coverage.xml', ['jacoco'], ['packaged', 'force-app']);
8071
});
81-
it('create 2 reports at once', async () => {
82-
await transformCoverageReport(deployCoverage, 'coverage.xml', ['sonar', 'cobertura'], ['samples']);
83-
});
8472
});

test/utils/baselineCompare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function compareToBaselines(): Promise<void> {
3131
for (const format of formatOptions as Array<keyof typeof baselineMap>) {
3232
for (const { label } of inputJsons) {
3333
const reportExtension = getExtensionForFormat(format);
34-
const outputPath = resolve(`${format}_${label}${reportExtension}`);
34+
const outputPath = resolve(`${label}-${format}${reportExtension}`);
3535
const outputContent = await readFile(outputPath, 'utf-8');
3636
const baselineContent = await readFile(baselineMap[format], 'utf-8');
3737

test/utils/testCleanup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function postTestCleanup(): Promise<void> {
1717
.flatMap((format) =>
1818
inputJsons.map(({ label }) => {
1919
const reportExtension = getExtensionForFormat(format);
20-
return resolve(`${format}_${label}${reportExtension}`);
20+
return resolve(`${label}-${format}${reportExtension}`);
2121
})
2222
)
2323
.concat(defaultPath);

0 commit comments

Comments
 (0)