Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: verify the SPV is availble to query, before checking deps #235

Merged
merged 7 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions src/commands/package/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,41 @@ export class Install extends SfCommand<PackageInstallRequest> {
this.warn(warningMsg);
});

if (flags.wait) {
let timeThen = Date.now();
// waiting for publish to finish
let remainingTime = flags['publish-wait'];

Lifecycle.getInstance().on(
PackageEvents.install['subscriber-status'],
// eslint-disable-next-line @typescript-eslint/require-await
async (publishStatus: PackagingSObjects.InstallValidationStatus) => {
const elapsedTime = Duration.milliseconds(Date.now() - timeThen);
timeThen = Date.now();
remainingTime = Duration.milliseconds(remainingTime.milliseconds - elapsedTime.milliseconds);
const status =
publishStatus === 'NO_ERRORS_DETECTED'
? messages.getMessage('availableForInstallation')
: messages.getMessage('unavailableForInstallation');
this.spinner.status = messages.getMessage('packagePublishWaitingStatus', [remainingTime.minutes, status]);
}
);

if (flags['publish-wait'].milliseconds > 0) {
this.spinner.start(
messages.getMessage('packagePublishWaitingStatus', [remainingTime.minutes, 'Querying Status'])
);

await this.subscriberPackageVersion.waitForPublish({
publishTimeout: flags['publish-wait'],
publishFrequency: Duration.seconds(10),
installationKey: flags['installation-key'],
});
// need to stop the spinner to avoid weird behavior with the prompts below
this.spinner.stop();
}
}

// If the user has specified --upgradetype Delete, then prompt for confirmation
// unless the noprompt option has been included.
if (flags['upgrade-type'] === 'Delete') {
Expand All @@ -155,21 +190,6 @@ export class Install extends SfCommand<PackageInstallRequest> {
let timeThen = Date.now();
this.spinner.start(messages.getMessage('packageInstallWaiting', [remainingTime.minutes]));

// waiting for publish to finish
Lifecycle.getInstance().on(
PackageEvents.install['subscriber-status'],
// eslint-disable-next-line @typescript-eslint/require-await
async (publishStatus: PackagingSObjects.InstallValidationStatus) => {
const elapsedTime = Duration.milliseconds(Date.now() - timeThen);
timeThen = Date.now();
remainingTime = Duration.milliseconds(remainingTime.milliseconds - elapsedTime.milliseconds);
const status =
publishStatus === 'NO_ERRORS_DETECTED'
? messages.getMessage('availableForInstallation')
: messages.getMessage('unavailableForInstallation');
this.spinner.status = messages.getMessage('packagePublishWaitingStatus', [remainingTime.minutes, status]);
}
);
// waiting for package install to finish
Lifecycle.getInstance().on(
PackageEvents.install.status,
Expand Down
41 changes: 25 additions & 16 deletions test/commands/package/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ describe('package:install', () => {

it('should listen for Package/install-status polling events and log statuses', async () => {
const successRequest = Object.assign({}, pkgInstallRequest, { Status: 'SUCCESS' });
const waitForPublishStub = stubMethod(
$$.SANDBOX,
SubscriberPackageVersion.prototype,
'waitForPublish'
).resolves();
installStub = stubMethod($$.SANDBOX, SubscriberPackageVersion.prototype, 'install').callsFake(async () => {
await Lifecycle.getInstance().emit(PackageEvents.install.status, pkgInstallRequest);
await Lifecycle.getInstance().emit(PackageEvents.install.status, successRequest);
Expand All @@ -356,15 +361,18 @@ describe('package:install', () => {
const result = await new Install(['-p', myPackageVersion04t, '-w', '1', '-o', testOrg.username], config).run();

expect(uxLogStub.calledOnce).to.be.true;
// expect(uxSetSpinnerStatusStub.args[0][0]).to.equal(
// '1 minutes remaining until timeout. Install status: IN_PROGRESS'
// );
// expect(uxSetSpinnerStatusStub.args[1][0]).to.equal('1 minutes remaining until timeout. Install status: SUCCESS');
expect(result).to.deep.equal(pkgInstallRequest);
// wait for publish should only be called when --publish-wait flag is passed
expect(waitForPublishStub.called).to.be.false;
});

it('should listen for Package/install-status and Package/install/subscriber-status polling events and log statuses', async () => {
const successRequest = Object.assign({}, pkgInstallRequest, { Status: 'SUCCESS' });
const waitForPublishStub = stubMethod(
$$.SANDBOX,
SubscriberPackageVersion.prototype,
'waitForPublish'
).resolves();
installStub = stubMethod($$.SANDBOX, SubscriberPackageVersion.prototype, 'install').callsFake(async () => {
await Lifecycle.getInstance().emit(
PackageEvents.install['subscriber-status'],
Expand All @@ -380,22 +388,23 @@ describe('package:install', () => {
});
stubMethod($$.SANDBOX, Connection.prototype, 'singleRecordQuery').resolves(subscriberPackageVersion);

const command = new Install(['-p', myPackageVersion04t, '-w', '1', '-b', '1', '-o', testOrg.username], config);
const command = new Install(['-p', myPackageVersion04t, '-w', '1', '-b', '2', '-o', testOrg.username], config);
const result = await command.run();

expect(uxLogStub.calledOnce).to.be.true;
// expect(uxSetSpinnerStatusStub.callCount).to.equal(4);
// expect(uxSetSpinnerStatusStub.args[0][0]).to.equal(
// '1 minutes remaining until timeout. Publish status: Unavailable for installation'
// );
// expect(uxSetSpinnerStatusStub.args[1][0]).to.equal(
// '1 minutes remaining until timeout. Publish status: Available for installation'
// );
// expect(uxSetSpinnerStatusStub.args[2][0]).to.equal(
// '1 minutes remaining until timeout. Install status: IN_PROGRESS'
// );
// expect(uxSetSpinnerStatusStub.args[3][0]).to.equal('1 minutes remaining until timeout. Install status: SUCCESS');
expect(result).to.deep.equal(pkgInstallRequest);
expect(waitForPublishStub.calledOnce).to.be.true;
expect(waitForPublishStub.args[0][0]).to.deep.equal({
installationKey: undefined,
publishFrequency: {
quantity: 10,
unit: 2,
},
publishTimeout: {
quantity: 2,
unit: 0,
},
});
});

describe('confirm upgrade type', () => {
Expand Down