Skip to content

Commit c194f7c

Browse files
fix: deploy:report now respects the wait flag (#153)
* fix: deploy:report now respects the wait flag * chore: fix build issue
1 parent 4cc5606 commit c194f7c

File tree

4 files changed

+62
-8
lines changed

4 files changed

+62
-8
lines changed

messages/report.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
"jobid": "job ID of the deployment you want to check; defaults to your most recent CLI deployment if not specified",
1616
"wait": "wait time for command to finish in minutes",
1717
"verbose": "verbose output of deploy result"
18-
}
18+
},
19+
"mdapiDeployFailed": "The metadata deploy operation failed."
1920
}

src/commands/force/source/deploy/report.ts

+24-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
import * as os from 'os';
99
import { Messages, SfdxProject } from '@salesforce/core';
1010
import { flags, FlagsConfig } from '@salesforce/command';
11-
import { Duration } from '@salesforce/kit';
11+
import { Duration, env } from '@salesforce/kit';
12+
import { MetadataApiDeploy } from '@salesforce/source-deploy-retrieve';
1213
import { DeployCommand } from '../../../../deployCommand';
1314
import {
1415
DeployReportCommandResult,
1516
DeployReportResultFormatter,
1617
} from '../../../../formatters/deployReportResultFormatter';
1718
import { ComponentSetBuilder } from '../../../../componentSetBuilder';
19+
import { ProgressFormatter } from '../../../../formatters/progressFormatter';
20+
import { DeployProgressBarFormatter } from '../../../../formatters/deployProgressBarFormatter';
21+
import { DeployProgressStatusFormatter } from '../../../../formatters/deployProgressStatusFormatter';
1822

1923
Messages.importMessagesDirectory(__dirname);
2024
const messages = Messages.loadMessages('@salesforce/plugin-source', 'report');
@@ -38,13 +42,21 @@ export class Report extends DeployCommand {
3842
description: messages.getMessage('flags.verbose'),
3943
}),
4044
};
41-
4245
public async run(): Promise<DeployReportCommandResult> {
4346
await this.doReport();
4447
this.resolveSuccess();
4548
return this.formatResult();
4649
}
4750

51+
/**
52+
* This method is here to provide a workaround to stubbing a constructor in the tests.
53+
*
54+
* @param id
55+
*/
56+
public createDeploy(id?: string): MetadataApiDeploy {
57+
return new MetadataApiDeploy({ usernameOrConnection: this.org.getUsername(), id });
58+
}
59+
4860
protected async doReport(): Promise<void> {
4961
const deployId = this.resolveDeployId(this.getFlag<string>('jobid'));
5062

@@ -61,6 +73,16 @@ export class Report extends DeployCommand {
6173
}
6274
this.componentSet = await ComponentSetBuilder.build({ sourcepath });
6375
}
76+
77+
const waitDuration = this.getFlag<Duration>('wait');
78+
const deploy = this.createDeploy(deployId);
79+
if (!this.isJsonOutput()) {
80+
const progressFormatter: ProgressFormatter = env.getBoolean('SFDX_USE_PROGRESS_BAR', true)
81+
? new DeployProgressBarFormatter(this.logger, this.ux)
82+
: new DeployProgressStatusFormatter(this.logger, this.ux);
83+
progressFormatter.progress(deploy);
84+
}
85+
await deploy.pollStatus(500, waitDuration.seconds);
6486
this.deployResult = await this.report(deployId);
6587
}
6688

src/formatters/deployReportResultFormatter.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8-
import { MetadataApiDeployStatus } from '@salesforce/source-deploy-retrieve/lib/src/client/types';
8+
import { MetadataApiDeployStatus, RequestStatus } from '@salesforce/source-deploy-retrieve/lib/src/client/types';
99
import { getString } from '@salesforce/ts-types';
10+
import { SfdxError } from '@salesforce/core';
1011
import { DeployResultFormatter } from './deployResultFormatter';
1112

1213
export type DeployReportCommandResult = MetadataApiDeployStatus;
@@ -35,10 +36,16 @@ export class DeployReportResultFormatter extends DeployResultFormatter {
3536
} else {
3637
this.ux.log('No components deployed');
3738
}
38-
return;
39+
} else {
40+
this.displaySuccesses();
41+
this.displayFailures();
42+
this.displayTestResults();
3943
}
40-
this.displaySuccesses();
41-
this.displayFailures();
42-
this.displayTestResults();
44+
45+
if (status === RequestStatus.Failed) {
46+
throw SfdxError.create('@salesforce/plugin-source', 'report', 'mdapiDeployFailed');
47+
}
48+
49+
return;
4350
}
4451
}

test/commands/source/report.test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ import { fromStub, spyMethod, stubInterface, stubMethod } from '@salesforce/ts-s
1212
import { ConfigFile, Org, SfdxProject } from '@salesforce/core';
1313
import { IConfig } from '@oclif/config';
1414
import { UX } from '@salesforce/command';
15+
import { MetadataApiDeploy } from '@salesforce/source-deploy-retrieve';
1516
import { Report } from '../../../src/commands/force/source/deploy/report';
1617
import { DeployReportResultFormatter } from '../../../src/formatters/deployReportResultFormatter';
1718
import { DeployCommandResult } from '../../../src/formatters/deployResultFormatter';
19+
import { DeployProgressBarFormatter } from '../../../src/formatters/deployProgressBarFormatter';
20+
import { DeployProgressStatusFormatter } from '../../../src/formatters/deployProgressStatusFormatter';
1821
import { getDeployResult } from './deployResponses';
1922

2023
describe('force:source:report', () => {
@@ -33,6 +36,7 @@ describe('force:source:report', () => {
3336
const oclifConfigStub = fromStub(stubInterface<IConfig>(sandbox));
3437
let checkDeployStatusStub: sinon.SinonStub;
3538
let uxLogStub: sinon.SinonStub;
39+
let pollStatusStub: sinon.SinonStub;
3640

3741
class TestReport extends Report {
3842
public async runIt() {
@@ -45,6 +49,11 @@ describe('force:source:report', () => {
4549
public setProject(project: SfdxProject) {
4650
this.project = project;
4751
}
52+
53+
public createDeploy(): MetadataApiDeploy {
54+
pollStatusStub = sandbox.stub(MetadataApiDeploy.prototype, 'pollStatus');
55+
return MetadataApiDeploy.prototype;
56+
}
4857
}
4958

5059
const runReportCmd = async (params: string[]) => {
@@ -91,9 +100,11 @@ describe('force:source:report', () => {
91100
});
92101

93102
it('should display stashed deploy ID', async () => {
103+
const progressBarStub = sandbox.stub(DeployProgressBarFormatter.prototype, 'progress').returns();
94104
const result = await runReportCmd([]);
95105
expect(result).to.deep.equal(expectedResults);
96106
expect(uxLogStub.firstCall.args[0]).to.contain(stashedDeployId);
107+
expect(progressBarStub.calledOnce).to.equal(true);
97108
});
98109

99110
it('should use the jobid flag', async () => {
@@ -105,18 +116,22 @@ describe('force:source:report', () => {
105116
});
106117

107118
it('should display the jobid flag', async () => {
119+
const progressBarStub = sandbox.stub(DeployProgressBarFormatter.prototype, 'progress').returns();
108120
const result = await runReportCmd(['--jobid', expectedResults.id]);
109121
expect(result).to.deep.equal(expectedResults);
110122
expect(uxLogStub.firstCall.args[0]).to.contain(expectedResults.id);
123+
expect(progressBarStub.calledOnce).to.equal(true);
111124
});
112125

113126
it('should display output with no --json', async () => {
114127
const displayStub = sandbox.stub(DeployReportResultFormatter.prototype, 'display');
128+
const progressBarStub = sandbox.stub(DeployProgressBarFormatter.prototype, 'progress').returns();
115129
const getJsonStub = sandbox.stub(DeployReportResultFormatter.prototype, 'getJson');
116130
await runReportCmd([]);
117131
expect(displayStub.calledOnce).to.equal(true);
118132
expect(getJsonStub.calledOnce).to.equal(true);
119133
expect(uxLogStub.called).to.equal(true);
134+
expect(progressBarStub.calledOnce).to.equal(true);
120135
});
121136

122137
it('should NOT display output with --json', async () => {
@@ -127,4 +142,13 @@ describe('force:source:report', () => {
127142
expect(getJsonStub.calledOnce).to.equal(true);
128143
expect(uxLogStub.called).to.equal(false);
129144
});
145+
146+
it('should call the correct progress method', async () => {
147+
const progressBarStub = sandbox.stub(DeployProgressBarFormatter.prototype, 'progress').returns();
148+
const progressStatusStub = sandbox.stub(DeployProgressStatusFormatter.prototype, 'progress').returns();
149+
await runReportCmd([]);
150+
expect(progressStatusStub.calledOnce).to.equal(false);
151+
expect(progressBarStub.calledOnce).to.equal(true);
152+
expect(pollStatusStub.calledOnce).to.equal(true);
153+
});
130154
});

0 commit comments

Comments
 (0)