Skip to content

Commit

Permalink
fix: support hooks for deployRecentValidation and async deploys (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele authored May 4, 2021
1 parent df63d5c commit ac787f9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/commands/force/source/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>('apiversion'),
sourcepath: this.getFlag<string[]>('sourcepath'),
Expand All @@ -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<boolean>('ignorewarnings', false),
rollbackOnError: !this.getFlag<boolean>('ignoreerrors', false),
checkOnly: this.getFlag<boolean>('checkonly', false),
runTests: this.getFlag<string[]>('runtests'),
testLevel: this.getFlag<TestLevel>('testlevel'),
},
});

const deploy = cs.deploy({
usernameOrConnection: this.org.getUsername(),
apiOptions: {
ignoreWarnings: this.getFlag<boolean>('ignorewarnings', false),
rollbackOnError: !this.getFlag<boolean>('ignoreerrors', false),
checkOnly: this.getFlag<boolean>('checkonly', false),
runTests: this.getFlag<string[]>('runtests'),
testLevel: this.getFlag<TestLevel>('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);
Expand Down
17 changes: 17 additions & 0 deletions test/commands/source/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

Expand Down Expand Up @@ -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');
});
});

0 comments on commit ac787f9

Please sign in to comment.