Skip to content

Commit ed04d33

Browse files
committed
fix: improve CI output, handle verbose output
1 parent d95f0a3 commit ed04d33

File tree

6 files changed

+45
-18
lines changed

6 files changed

+45
-18
lines changed

src/commands/project/delete/source.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ export class Source extends SfCommand<DeleteSourceJson> {
248248
const stages = new DeployStages({
249249
title: 'Deleting Metadata',
250250
jsonEnabled: this.jsonEnabled(),
251+
verbose: this.flags['verbose'],
251252
});
252253

253254
const isRest = (await resolveApi()) === API['REST'];

src/commands/project/deploy/resume.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export default class DeployMetadataResume extends SfCommand<DeployResultJson> {
134134
new DeployStages({
135135
title: 'Resuming Deploy',
136136
jsonEnabled: this.jsonEnabled(),
137+
verbose: flags.verbose,
137138
}).start(
138139
{
139140
deploy,

src/commands/project/deploy/start.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
250250
this.stages = new DeployStages({
251251
title,
252252
jsonEnabled: this.jsonEnabled(),
253+
verbose: flags['verbose'],
253254
});
254255

255256
this.deployUrl = buildDeployUrl(flags['target-org'], deploy.id);

src/commands/project/deploy/validate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ export default class DeployMetadataValidate extends SfCommand<DeployResultJson>
211211
new DeployStages({
212212
title: 'Validating Deployment',
213213
jsonEnabled: this.jsonEnabled(),
214+
verbose: flags.verbose,
214215
}).start(
215216
{
216217
deploy,

src/formatters/testResultsFormatter.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ import {
1818
Successes,
1919
} from '@salesforce/source-deploy-retrieve';
2020
import { ensureArray } from '@salesforce/kit';
21-
import { isTruthy, TestLevel, Verbosity } from '../utils/types.js';
21+
import { TestLevel, Verbosity } from '../utils/types.js';
2222
import { tableHeader, error, success, check } from '../utils/output.js';
2323
import { coverageOutput } from '../utils/coverage.js';
24+
import { isCI } from '../utils/deployStages.js';
2425

2526
const ux = new Ux();
2627

@@ -45,12 +46,14 @@ export class TestResultsFormatter {
4546
return;
4647
}
4748

48-
if (!isTruthy(process.env.CI)) {
49+
if (!isCI()) {
4950
displayVerboseTestFailures(this.result.response);
5051
}
5152

5253
if (this.verbosity === 'verbose') {
53-
displayVerboseTestSuccesses(this.result.response.details.runTestResult?.successes);
54+
if (!isCI()) {
55+
displayVerboseTestSuccesses(this.result.response.details.runTestResult?.successes);
56+
}
5457
displayVerboseTestCoverage(this.result.response.details.runTestResult?.codeCoverage);
5558
}
5659

@@ -124,7 +127,7 @@ const displayVerboseTestCoverage = (coverage?: CodeCoverage | CodeCoverage[]): v
124127
}
125128
};
126129

127-
const testResultSort = <T extends Successes | Failures>(a: T, b: T): number =>
130+
export const testResultSort = <T extends Successes | Failures>(a: T, b: T): number =>
128131
a.methodName === b.methodName ? a.name.localeCompare(b.name) : a.methodName.localeCompare(b.methodName);
129132

130133
const coverageSort = (a: CodeCoverage, b: CodeCoverage): number =>

src/utils/deployStages.ts

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,13 @@
77
import os from 'node:os';
88
import { MultiStageOutput } from '@oclif/multi-stage-output';
99
import { Lifecycle, Messages } from '@salesforce/core';
10-
import {
11-
Failures,
12-
MetadataApiDeploy,
13-
MetadataApiDeployStatus,
14-
RequestStatus,
15-
Successes,
16-
} from '@salesforce/source-deploy-retrieve';
10+
import { MetadataApiDeploy, MetadataApiDeployStatus, RequestStatus } from '@salesforce/source-deploy-retrieve';
1711
import { SourceMemberPollingEvent } from '@salesforce/source-tracking';
1812
import terminalLink from 'terminal-link';
1913
import { ensureArray } from '@salesforce/kit';
2014
import ansis from 'ansis';
21-
import { getZipFileSize } from './output.js';
15+
import { testResultSort } from '../formatters/testResultsFormatter.js';
16+
import { check, getZipFileSize } from './output.js';
2217
import { isTruthy } from './types.js';
2318

2419
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
@@ -27,6 +22,7 @@ const mdTransferMessages = Messages.loadMessages('@salesforce/plugin-deploy-retr
2722
type Options = {
2823
title: string;
2924
jsonEnabled: boolean;
25+
verbose?: boolean;
3026
};
3127

3228
type Data = {
@@ -58,7 +54,7 @@ function formatProgress(current: number, total: number): string {
5854
export class DeployStages {
5955
private mso: MultiStageOutput<Data>;
6056

61-
public constructor({ title, jsonEnabled }: Options) {
57+
public constructor({ title, jsonEnabled, verbose }: Options) {
6258
this.mso = new MultiStageOutput<Data>({
6359
title,
6460
stages: [
@@ -142,7 +138,8 @@ export class DeployStages {
142138
label: 'Successful',
143139
get: (data): string | undefined =>
144140
data?.mdapiDeploy?.numberTestsTotal && data?.mdapiDeploy?.numberTestsCompleted
145-
? formatProgress(data?.mdapiDeploy?.numberTestsCompleted, data?.mdapiDeploy?.numberTestsTotal)
141+
? formatProgress(data?.mdapiDeploy?.numberTestsCompleted, data?.mdapiDeploy?.numberTestsTotal) +
142+
(verbose && isCI() ? os.EOL + formatTestSuccesses(data) : '')
146143
: undefined,
147144
stage: 'Running Tests',
148145
type: 'dynamic-key-value',
@@ -152,7 +149,7 @@ export class DeployStages {
152149
get: (data): string | undefined =>
153150
data?.mdapiDeploy?.numberTestsTotal && data?.mdapiDeploy?.numberTestErrors
154151
? formatProgress(data?.mdapiDeploy?.numberTestErrors, data?.mdapiDeploy?.numberTestsTotal) +
155-
(isTruthy(process.env.CI) ? os.EOL + formatTestFailures(data) : '')
152+
(isCI() ? os.EOL + formatTestFailures(data) : '')
156153
: undefined,
157154
stage: 'Running Tests',
158155
type: 'dynamic-key-value',
@@ -253,8 +250,22 @@ export class DeployStages {
253250
}
254251
}
255252

253+
function formatTestSuccesses(data: Data): string {
254+
const successes = ensureArray(data.mdapiDeploy.details.runTestResult?.successes).sort(testResultSort);
255+
256+
let output = '';
257+
258+
if (successes.length > 0) {
259+
for (const test of successes) {
260+
const testName = ansis.underline(`${test.name}.${test.methodName}`);
261+
output += ` ${check} ${testName}${os.EOL}`;
262+
}
263+
}
264+
265+
return output;
266+
}
267+
256268
function formatTestFailures(data: Data): string {
257-
if (data.mdapiDeploy.details.runTestResult?.failures === undefined) return '';
258269
const failures = ensureArray(data.mdapiDeploy.details.runTestResult?.failures).sort(testResultSort);
259270

260271
let output = '';
@@ -273,5 +284,14 @@ function formatTestFailures(data: Data): string {
273284
return output.slice(0, -1);
274285
}
275286

276-
const testResultSort = <T extends Successes | Failures>(a: T, b: T): number =>
277-
a.methodName === b.methodName ? a.name.localeCompare(b.name) : a.methodName.localeCompare(b.methodName);
287+
export function isCI(): boolean {
288+
if (
289+
isTruthy(process.env.CI) &&
290+
('CI' in process.env ||
291+
'CONTINUOUS_INTEGRATION' in process.env ||
292+
Object.keys(process.env).some((key) => key.startsWith('CI_')))
293+
)
294+
return true;
295+
296+
return false;
297+
}

0 commit comments

Comments
 (0)