Skip to content

Commit 0018dd6

Browse files
feat: add test result formatter flags, outputdir flags, junit flag
1 parent 5c032e6 commit 0018dd6

File tree

13 files changed

+426
-31
lines changed

13 files changed

+426
-31
lines changed

command-snapshot.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,23 @@
7474
{
7575
"command": "project:deploy:report",
7676
"plugin": "@salesforce/plugin-deploy-retrieve",
77-
"flags": ["job-id", "json", "use-most-recent"],
77+
"flags": ["coverage-formatters", "job-id", "json", "junit", "results-dir", "use-most-recent"],
7878
"alias": ["deploy:metadata:report"]
7979
},
8080
{
8181
"command": "project:deploy:resume",
8282
"plugin": "@salesforce/plugin-deploy-retrieve",
83-
"flags": ["concise", "job-id", "json", "use-most-recent", "verbose", "wait"],
83+
"flags": [
84+
"concise",
85+
"coverage-formatters",
86+
"job-id",
87+
"json",
88+
"junit",
89+
"results-dir",
90+
"use-most-recent",
91+
"verbose",
92+
"wait"
93+
],
8494
"alias": ["deploy:metadata:resume"]
8595
},
8696
{
@@ -90,14 +100,17 @@
90100
"api-version",
91101
"async",
92102
"concise",
103+
"coverage-formatters",
93104
"dry-run",
94105
"ignore-conflicts",
95106
"ignore-errors",
96107
"ignore-warnings",
97108
"json",
109+
"junit",
98110
"manifest",
99111
"metadata",
100112
"metadata-dir",
113+
"results-dir",
101114
"single-package",
102115
"source-dir",
103116
"target-org",

messages/deploy.metadata.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,19 @@ No local changes to deploy.
210210
# error.nothingToDeploy.Actions
211211

212212
- To see conflicts and ignored files, run "sf project deploy preview" with any of the manifest, directory, or metadata flags.
213+
214+
# flags.junit
215+
216+
output JUnit test results
217+
218+
# flags.coverage-formatters
219+
220+
format of the code coverage results
221+
222+
# flags.results-dir
223+
224+
output directory for code coverage and JUnit results; defaults to the deploy ID
225+
226+
# asyncCoverageJunitWarning
227+
228+
You requested an async deploy with code coverage or JUnit results. The reports will be available when the deploy completes.

messages/deploy.metadata.report.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,15 @@ Use the job ID of the most recent deploy operation.
4040
# flags.use-most-recent.description
4141

4242
For performance reasons, this flag uses job IDs for deploy operations that started only in the past 3 days or less. If your most recent operation was more than 3 days ago, this flag won't find a job ID.
43+
44+
# flags.junit
45+
46+
output JUnit test results
47+
48+
# flags.coverage-formatters
49+
50+
format of the code coverage results
51+
52+
# flags.results-dir
53+
54+
output directory for code coverage and JUnit results; defaults to the deploy ID

messages/deploy.metadata.resume.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,15 @@ Show concise output of the deploy operation result.
6060
# error.DeployNotResumable
6161

6262
Job ID %s is not resumable with status %s.
63+
64+
# flags.junit
65+
66+
output JUnit test results
67+
68+
# flags.coverage-formatters
69+
70+
format of the code coverage results
71+
72+
# flags.results-dir
73+
74+
output directory for code coverage and JUnit results; defaults to the deploy ID

src/commands/project/deploy/report.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { buildComponentSet } from '../../../utils/deploy';
1313
import { DeployCache } from '../../../utils/deployCache';
1414
import { DeployReportResultFormatter } from '../../../utils/output';
1515
import { DeployResultJson } from '../../../utils/types';
16+
import { reportsFormatters } from './start';
1617

1718
Messages.importMessagesDirectory(__dirname);
1819
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'deploy.metadata.report');
@@ -40,6 +41,17 @@ export default class DeployMetadataReport extends SfCommand<DeployResultJson> {
4041
summary: messages.getMessage('flags.use-most-recent.summary'),
4142
exactlyOne: ['use-most-recent', 'job-id'],
4243
}),
44+
'coverage-formatters': Flags.string({
45+
multiple: true,
46+
summary: messages.getMessage('flags.coverage-formatters'),
47+
options: reportsFormatters,
48+
helpValue: reportsFormatters.join(','),
49+
}),
50+
junit: Flags.boolean({ summary: messages.getMessage('flags.junit') }),
51+
'results-dir': Flags.directory({
52+
dependsOn: ['junit', 'coverage-formatters'],
53+
summary: messages.getMessage('flags.results-dir'),
54+
}),
4355
};
4456

4557
public async run(): Promise<DeployResultJson> {
@@ -53,7 +65,10 @@ export default class DeployMetadataReport extends SfCommand<DeployResultJson> {
5365
const componentSet = await buildComponentSet({ ...deployOpts, wait: Duration.minutes(deployOpts.wait) });
5466
const result = new DeployResult(deployStatus as unknown as MetadataApiDeployStatus, componentSet);
5567

56-
const formatter = new DeployReportResultFormatter(result, deployOpts);
68+
const formatter = new DeployReportResultFormatter(result, {
69+
...deployOpts,
70+
...{ 'target-org': flags['target-org'] as Org },
71+
});
5772

5873
if (!this.jsonEnabled()) formatter.display();
5974

src/commands/project/deploy/resume.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { DeployResultJson } from '../../../utils/types';
1515
import { determineExitCode, executeDeploy, isNotResumable } from '../../../utils/deploy';
1616
import { DeployCache } from '../../../utils/deployCache';
1717
import { DEPLOY_STATUS_CODES_DESCRIPTIONS } from '../../../utils/errorCodes';
18+
import { reportsFormatters } from './start';
1819

1920
Messages.importMessagesDirectory(__dirname);
2021
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'deploy.metadata.resume');
@@ -60,6 +61,17 @@ export default class DeployMetadataResume extends SfCommand<DeployResultJson> {
6061
helpValue: '<minutes>',
6162
min: 1,
6263
}),
64+
'coverage-formatters': Flags.string({
65+
multiple: true,
66+
summary: messages.getMessage('flags.coverage-formatters'),
67+
options: reportsFormatters,
68+
helpValue: reportsFormatters.join(','),
69+
}),
70+
junit: Flags.boolean({ summary: messages.getMessage('flags.junit') }),
71+
'results-dir': Flags.directory({
72+
dependsOn: ['junit', 'coverage-formatters'],
73+
summary: messages.getMessage('flags.results-dir'),
74+
}),
6375
};
6476

6577
public static envVariablesSection = toHelpSection('ENVIRONMENT VARIABLES', EnvironmentVariable.SF_USE_PROGRESS_BAR);

src/commands/project/deploy/start.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { bold } from 'chalk';
88
import { EnvironmentVariable, Messages, OrgConfigProperties, SfError } from '@salesforce/core';
99
import { SfCommand, toHelpSection, Flags } from '@salesforce/sf-plugins-core';
1010
import { SourceConflictError } from '@salesforce/source-tracking';
11+
import { DefaultReportOptions } from '@salesforce/apex-node';
1112
import { AsyncDeployResultFormatter, DeployResultFormatter, getVersionMessage } from '../../../utils/output';
1213
import { DeployProgress } from '../../../utils/progressBar';
1314
import { DeployResultJson, TestLevel } from '../../../utils/types';
@@ -20,6 +21,7 @@ import { writeConflictTable } from '../../../utils/conflicts';
2021

2122
Messages.importMessagesDirectory(__dirname);
2223
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'deploy.metadata');
24+
export const reportsFormatters = Object.keys(DefaultReportOptions);
2325

2426
const exclusiveFlags = ['manifest', 'source-dir', 'metadata', 'metadata-dir'];
2527

@@ -129,6 +131,17 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
129131
min: 1,
130132
exclusive: ['async'],
131133
}),
134+
'coverage-formatters': Flags.string({
135+
multiple: true,
136+
summary: messages.getMessage('flags.coverage-formatters'),
137+
options: reportsFormatters,
138+
helpValue: reportsFormatters.join(','),
139+
}),
140+
junit: Flags.boolean({ summary: messages.getMessage('flags.junit') }),
141+
'results-dir': Flags.directory({
142+
dependsOn: ['junit', 'coverage-formatters'],
143+
summary: messages.getMessage('flags.results-dir'),
144+
}),
132145
};
133146

134147
public static configurationVariablesSection = toHelpSection(
@@ -167,6 +180,9 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
167180
this.log(`Deploy ID: ${bold(deploy.id)}`);
168181

169182
if (flags.async) {
183+
if (flags['coverage-formatters']) {
184+
this.warn(messages.getMessage('asyncCoverageJunitWarning'));
185+
}
170186
const asyncFormatter = new AsyncDeployResultFormatter(deploy.id);
171187
if (!this.jsonEnabled()) asyncFormatter.display();
172188
return asyncFormatter.getJson();

src/utils/deploy.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ export type CachedOptions = Omit<DeployOptions, 'wait' | 'metadata' | 'source-di
6363
} & Partial<Pick<DeployOptions, 'manifest'>>;
6464

6565
export function validateTests(testLevel: TestLevel, tests: Nullable<string[]>): boolean {
66-
if (testLevel === TestLevel.RunSpecifiedTests && (tests ?? []).length === 0) return false;
67-
return true;
66+
return !(testLevel === TestLevel.RunSpecifiedTests && (tests ?? []).length === 0);
6867
}
6968

7069
export async function resolveApi(): Promise<API> {

src/utils/metadataDeployer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
NamedPackageDir,
1818
OrgAuthorization,
1919
OrgConfigProperties,
20+
Org,
2021
} from '@salesforce/core';
2122
import { Deployable, Deployer, DeployerResult, generateTableChoices } from '@salesforce/sf-plugins-core';
2223

@@ -141,6 +142,7 @@ export class MetadataDeployer extends Deployer {
141142
'test-level': this.testLevel,
142143
verbose: false,
143144
concise: false,
145+
'target-org': await Org.create({ aliasOrUsername: this.username }),
144146
});
145147
formatter.display();
146148
const deployerResult: DeployerResult = {

0 commit comments

Comments
 (0)