diff --git a/src/commands/force/source/deploy.ts b/src/commands/force/source/deploy.ts index dfcd98f41..da0a86c97 100644 --- a/src/commands/force/source/deploy.ts +++ b/src/commands/force/source/deploy.ts @@ -120,10 +120,8 @@ export class Deploy extends DeployCommand { if (this.flags.validateddeployrequestid) { this.deployResult = await this.deployRecentValidation(); - } else if (this.isAsync) { - // This is an async deploy. We just kick off the request. - throw Error('ASYNC DEPLOYS NOT IMPLEMENTED YET'); } else { + // the deployment involves a component set const cs = await ComponentSetBuilder.build({ apiversion: this.getFlag('apiversion'), sourcepath: this.getFlag('sourcepath'), @@ -136,27 +134,31 @@ export class Deploy extends DeployCommand { directoryPaths: this.getPackageDirs(), }, }); - + // fire predeploy event for sync and async deploys await this.lifecycle.emit('predeploy', cs.toArray()); + if (this.isAsync) { + // This is an async deploy. We just kick off the request. + throw Error('ASYNC DEPLOYS NOT IMPLEMENTED YET'); + } else { + const deploy = cs.deploy({ + usernameOrConnection: this.org.getUsername(), + apiOptions: { + ignoreWarnings: this.getFlag('ignorewarnings', false), + rollbackOnError: !this.getFlag('ignoreerrors', false), + checkOnly: this.getFlag('checkonly', false), + runTests: this.getFlag('runtests'), + testLevel: this.getFlag('testlevel'), + }, + }); - const deploy = cs.deploy({ - usernameOrConnection: this.org.getUsername(), - apiOptions: { - ignoreWarnings: this.getFlag('ignorewarnings', false), - rollbackOnError: !this.getFlag('ignoreerrors', false), - checkOnly: this.getFlag('checkonly', false), - runTests: this.getFlag('runtests'), - testLevel: this.getFlag('testlevel'), - }, - }); + // if SFDX_USE_PROGRESS_BAR is unset or true (default true) AND we're not print JSON output + if (env.getBoolean('SFDX_USE_PROGRESS_BAR', true) && !this.isJsonOutput()) { + this.initProgressBar(); + this.progress(deploy); + } - // if SFDX_USE_PROGRESS_BAR is unset or true (default true) AND we're not print JSON output - if (env.getBoolean('SFDX_USE_PROGRESS_BAR', true) && !this.isJsonOutput()) { - this.initProgressBar(); - this.progress(deploy); + this.deployResult = await deploy.start(); } - - this.deployResult = await deploy.start(); } await this.lifecycle.emit('postdeploy', this.deployResult); diff --git a/test/commands/source/deploy.test.ts b/test/commands/source/deploy.test.ts index a2560e9ed..8e5a29883 100644 --- a/test/commands/source/deploy.test.ts +++ b/test/commands/source/deploy.test.ts @@ -73,6 +73,7 @@ describe('force:source:deploy', () => { progressStub = stubMethod(sandbox, cmd, 'progress'); stubMethod(sandbox, UX.prototype, 'log'); stubMethod(sandbox, DeployResultFormatter.prototype, 'display'); + stubMethod(sandbox, Deploy.prototype, 'deployRecentValidation').resolves({}); return cmd.runIt(); }; @@ -259,4 +260,20 @@ describe('force:source:deploy', () => { ensureHookArgs(); ensureProgressBar(1); }); + + it('should emit postdeploy hooks for validateddeployrequestid deploys', async () => { + await runDeployCmd(['--validateddeployrequestid', '0Af0x00000pkAXLCA2']); + expect(lifecycleEmitStub.firstCall.args[0]).to.equal('postdeploy'); + }); + + it('should emit predeploy hooks for async deploys', async () => { + const sourcepath = ['somepath']; + try { + await runDeployCmd(['--sourcepath', sourcepath[0], '--wait', '0']); + } catch (e) { + // once async deploys supported remove the try/catch + expect((e as Error).message).to.include('NOT IMPLEMENTED YET'); + } + expect(lifecycleEmitStub.firstCall.args[0]).to.equal('predeploy'); + }); });