Skip to content

Commit 1d9beea

Browse files
authored
fix: move code from command into function (#184)
1 parent a2d045b commit 1d9beea

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

src/commands/acc-transformer/transform.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1010
const messages = Messages.loadMessages('apex-code-coverage-transformer', 'transformer.transform');
1111

1212
export default class TransformerTransform extends SfCommand<TransformerTransformResult> {
13-
public static readonly summary = messages.getMessage('summary');
14-
public static readonly description = messages.getMessage('description');
15-
public static readonly examples = messages.getMessages('examples');
13+
public static override readonly summary = messages.getMessage('summary');
14+
public static override readonly description = messages.getMessage('description');
15+
public static override readonly examples = messages.getMessages('examples');
1616

17-
public static readonly flags = {
17+
public static override readonly flags = {
1818
'coverage-json': Flags.file({
1919
summary: messages.getMessage('flags.coverage-json.summary'),
2020
char: 'j',
@@ -44,32 +44,24 @@ export default class TransformerTransform extends SfCommand<TransformerTransform
4444

4545
public async run(): Promise<TransformerTransformResult> {
4646
const { flags } = await this.parse(TransformerTransform);
47-
const jsonFilePath = flags['coverage-json'];
48-
const outputReportPath = flags['output-report'];
49-
const ignoreDirs = flags['ignore-package-directory'] ?? [];
50-
const format = flags['format'];
51-
let finalPath = outputReportPath;
52-
5347
const warnings: string[] = [];
5448

55-
try {
56-
const result = await transformCoverageReport(jsonFilePath, outputReportPath, format, ignoreDirs);
57-
warnings.push(...result.warnings);
58-
finalPath = result.finalPath;
59-
} catch (err) {
60-
this.error(
61-
'The provided JSON does not match a known coverage data format from the Salesforce deploy or test command.'
62-
);
63-
}
49+
const result = await transformCoverageReport(
50+
flags['coverage-json'],
51+
flags['output-report'],
52+
flags['format'],
53+
flags['ignore-package-directory'] ?? []
54+
);
55+
warnings.push(...result.warnings);
56+
const finalPath = result.finalPath;
6457

65-
// Print warnings if any
6658
if (warnings.length > 0) {
6759
warnings.forEach((warning) => {
6860
this.warn(warning);
6961
});
7062
}
7163

7264
this.log(`The coverage report has been written to ${finalPath}`);
73-
return { path: outputReportPath };
65+
return { path: finalPath };
7466
}
7567
}

src/transformers/coverageTransformer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ export async function transformCoverageReport(
7272
filesProcessed++;
7373
});
7474
} else {
75-
throw new Error('Unknown coverage data type. Cannot generate report.');
75+
throw new Error(
76+
'The provided JSON does not match a known coverage data format from the Salesforce deploy or test command.'
77+
);
7678
}
7779

7880
if (filesProcessed === 0) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('acc-transformer transform NUTs', () => {
4343

4444
it('confirms a failure on an invalid JSON file.', async () => {
4545
const command = `acc-transformer transform --coverage-json "${invalidJson}"`;
46-
const error = execCmd(command, { ensureExitCode: 2 }).shellOutput.stderr;
46+
const error = execCmd(command, { ensureExitCode: 1 }).shellOutput.stderr;
4747

4848
expect(error.replace('\n', '')).to.contain(
4949
'The provided JSON does not match a known coverage data format from the Salesforce deploy or test command.'

0 commit comments

Comments
 (0)