Skip to content

Commit

Permalink
Merge pull request #70 from salesforcecli/wr/standardizeEventNames
Browse files Browse the repository at this point in the history
fix: update lifecycle event names
  • Loading branch information
peternhale authored Sep 15, 2022
2 parents 83c104b + 922fca9 commit a9814ab
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 507 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
"dependencies": {
"@oclif/core": "^1.14.2",
"@salesforce/command": "^5.2.6",
"@salesforce/core": "^3.26.2",
"@salesforce/core": "^3.3.0",
"@salesforce/kit": "^1.6.0",
"@salesforce/packaging": "^0.0.35",
"@salesforce/packaging": "^0.0.36",
"tslib": "^2",
"chalk": "^4.1.2"
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^3.1.3",
"@oclif/plugin-version": "^1.1.2",
"@salesforce/cli-plugins-testkit": "^1.5.35",
"@salesforce/cli-plugins-testkit": "^2.3.13",
"@salesforce/dev-config": "^2.1.3",
"@salesforce/dev-scripts": "^1.0.4",
"@salesforce/plugin-auth": "^2.2.3",
Expand Down Expand Up @@ -181,11 +181,11 @@
"test": "sf-test",
"test:command-reference": "./bin/run commandreference:generate --erroronwarnings",
"test:deprecation-policy": "./bin/run snapshot:compare",
"test:nuts": "nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 600000 --parallel",
"test:nuts": "nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 1800000",
"test:nuts:package1": "nyc mocha \"**/package1/*.nut.ts\" --slow 4500 --timeout 600000 --parallel",
"version": "oclif readme"
},
"publishConfig": {
"access": "public"
}
}
}
7 changes: 3 additions & 4 deletions src/commands/force/package/beta/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ import {
convertCamelCaseStringToSentence,
INSTALL_URL_BASE,
Package,
PackageEvents,
PackageVersionCreateEventData,
PackageVersionCreateRequestResult,
PackagingSObjects,
} from '@salesforce/packaging';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_convert');
const pvcMessages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_version_create');
const Package2VersionStatus = PackagingSObjects.Package2VersionStatus;

export class PackageConvert extends SfdxCommand {
public static readonly description = messages.getMessage('cliDescription');
Expand Down Expand Up @@ -64,7 +63,7 @@ export class PackageConvert extends SfdxCommand {

public async run(): Promise<PackageVersionCreateRequestResult> {
// eslint-disable-next-line @typescript-eslint/require-await
Lifecycle.getInstance().on(Package2VersionStatus.inProgress, async (data: PackageVersionCreateEventData) => {
Lifecycle.getInstance().on(PackageEvents.convert.progress, async (data: PackageVersionCreateEventData) => {
this.ux.log(
`Request in progress. Sleeping 30 seconds. Will wait a total of ${
data.timeRemaining.seconds
Expand All @@ -75,7 +74,7 @@ export class PackageConvert extends SfdxCommand {
});

// eslint-disable-next-line @typescript-eslint/require-await
Lifecycle.getInstance().on(Package2VersionStatus.success, async () => {
Lifecycle.getInstance().on(PackageEvents.convert.success, async () => {
this.ux.log('SUCCESS');
});

Expand Down
13 changes: 7 additions & 6 deletions src/commands/force/package/beta/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Duration } from '@salesforce/kit';
import {
getPackageTypeBy04t,
Package,
PackageEvents,
PackageInstallCreateRequest,
PackageInstallOptions,
PackagingSObjects,
Expand Down Expand Up @@ -105,7 +106,7 @@ export class Install extends SfdxCommand {
};

// eslint-disable-next-line @typescript-eslint/require-await
Lifecycle.getInstance().on('PackageInstallRequest:warning', async (warningMsg: string) => {
Lifecycle.getInstance().on(PackageEvents.install.warning, async (warningMsg: string) => {
this.ux.log(warningMsg);
});

Expand Down Expand Up @@ -133,7 +134,7 @@ export class Install extends SfdxCommand {
this.ux.startSpinner(messages.getMessage('packageInstallWaiting', [remainingTime.minutes]));

// eslint-disable-next-line @typescript-eslint/require-await
Lifecycle.getInstance().on('PackageInstallRequest:status', async (piRequest: PackageInstallRequest) => {
Lifecycle.getInstance().on(PackageEvents.install.status, async (piRequest: PackageInstallRequest) => {
const elapsedTime = Duration.milliseconds(Date.now() - timeThen);
timeThen = Date.now();
remainingTime = Duration.milliseconds(remainingTime.milliseconds - elapsedTime.milliseconds);
Expand All @@ -159,9 +160,9 @@ export class Install extends SfdxCommand {

protected async finally(err: Optional<Error>): Promise<void> {
// Remove all the event listeners or they will still handle events
Lifecycle.getInstance().removeAllListeners('PackageInstallRequest:warning');
Lifecycle.getInstance().removeAllListeners('PackageInstallRequest:status');
Lifecycle.getInstance().removeAllListeners('SubscriberPackageVersion:status');
Lifecycle.getInstance().removeAllListeners(PackageEvents.install.warning);
Lifecycle.getInstance().removeAllListeners(PackageEvents.install.status);
Lifecycle.getInstance().removeAllListeners(PackageEvents.install['subscriber-status']);
await super.finally(err);
}

Expand Down Expand Up @@ -191,7 +192,7 @@ export class Install extends SfdxCommand {

private async waitForPublish(request: PackageInstallCreateRequest): Promise<void> {
// eslint-disable-next-line @typescript-eslint/require-await
Lifecycle.getInstance().on('SubscriberPackageVersion:status', async (status: string) => {
Lifecycle.getInstance().on(PackageEvents.install['subscriber-status'], async (status: string) => {
const tokens = status ? [` Status = ${status}`] : [];
this.ux.log(messages.getMessage('publishWaitProgress', tokens));
});
Expand Down
4 changes: 2 additions & 2 deletions src/commands/force/package/beta/uninstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import * as os from 'os';
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
import { Lifecycle, Messages, SfProject } from '@salesforce/core';
import { Package, PackagingSObjects, uninstallPackage } from '@salesforce/packaging';
import { Package, PackageEvents, PackagingSObjects, uninstallPackage } from '@salesforce/packaging';
import { Duration } from '@salesforce/kit';

type UninstallResult = PackagingSObjects.SubscriberPackageVersionUninstallRequest;
Expand Down Expand Up @@ -39,7 +39,7 @@ export class PackageUninstallCommand extends SfdxCommand {
public async run(): Promise<UninstallResult> {
// no awaits in async method
// eslint-disable-next-line @typescript-eslint/require-await
Lifecycle.getInstance().on('packageUninstall', async (data: UninstallResult) => {
Lifecycle.getInstance().on(PackageEvents.uninstall, async (data: UninstallResult) => {
// Request still in progress. Just print a console message and move on. Server will be polled again.
this.ux.log(`Waiting for the package uninstall request to get processed. Status = ${data.Status}`);
});
Expand Down
22 changes: 13 additions & 9 deletions src/commands/force/package/beta/version/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
INSTALL_URL_BASE,
PackageVersion,
PackageVersionCreateReportProgress,
PackageVersionEvents,
PackagingSObjects,
} from '@salesforce/packaging';
import Package2VersionStatus = PackagingSObjects.Package2VersionStatus;
Expand Down Expand Up @@ -155,17 +156,20 @@ export class PackageVersionCreateCommand extends SfdxCommand {
this.ux.warn(messages.getMessage('skipValidationWarning'));
}
const frequency = this.flags.wait && this.flags.skipvalidation ? Duration.seconds(5) : Duration.seconds(30);
// no async methods
// eslint-disable-next-line @typescript-eslint/require-await
Lifecycle.getInstance().on('in-progress', async (data: PackageVersionCreateReportProgress) => {
if (data.Status !== Package2VersionStatus.success && data.Status !== Package2VersionStatus.error) {
this.ux.setSpinnerStatus(
messages.getMessage('packageVersionCreateWaitingStatus', [data.remainingWaitTime.minutes, data.Status])
);
Lifecycle.getInstance().on(
PackageVersionEvents.create.progress,
// no async methods
// eslint-disable-next-line @typescript-eslint/require-await
async (data: PackageVersionCreateReportProgress) => {
if (data.Status !== Package2VersionStatus.success && data.Status !== Package2VersionStatus.error) {
this.ux.setSpinnerStatus(
messages.getMessage('packageVersionCreateWaitingStatus', [data.remainingWaitTime.minutes, data.Status])
);
}
}
});
);
Lifecycle.getInstance().on(
'packageVersionCreate:preserveFiles',
PackageVersionEvents.create['preserve-files'],
// eslint-disable-next-line @typescript-eslint/require-await
async (data: { location: string; message: string }) => {
this.ux.log(messages.getMessage('tempFileLocation', [data.location]));
Expand Down
4 changes: 2 additions & 2 deletions src/commands/force/package1/beta/version/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
import { Lifecycle, Messages } from '@salesforce/core';
import { Duration } from '@salesforce/kit';
import { package1VersionCreate, PackagingSObjects } from '@salesforce/packaging';
import { package1VersionCreate, PackageVersionEvents, PackagingSObjects } from '@salesforce/packaging';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package1_version_create');
Expand Down Expand Up @@ -74,7 +74,7 @@ export class Package1VersionCreateCommand extends SfdxCommand {
if (this.flags.wait) {
// if we're waiting for the request, set up the listener
Lifecycle.getInstance().on(
'package1VersionCreate:progress',
PackageVersionEvents.create.progress,
// the 'on' method requires an async method, but we don't have any async calls
// eslint-disable-next-line @typescript-eslint/require-await
async (data: { timeout: number; pollingResult: PackageUploadRequest }) => {
Expand Down
4 changes: 3 additions & 1 deletion test/commands/force/package/install.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { expect } from 'chai';
import { PackagingSObjects } from '@salesforce/packaging';
import { Duration } from '@salesforce/kit';

type PackageInstallRequest = PackagingSObjects.PackageInstallRequest;
type PackageUninstallRequest = PackagingSObjects.SubscriberPackageVersionUninstallRequest;
Expand All @@ -28,7 +29,8 @@ describe('package install', () => {
it('should install ElectronBranding package with polling', function () {
const command = 'force:package:beta:install -p 04t6A000002zgKSQAY -w 20';
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout as string;
const output = execCmd(command, { ensureExitCode: 0, timeout: Duration.minutes(20).milliseconds }).shellOutput
.stdout;
expect(output).to.contain('Successfully installed package');
});

Expand Down
16 changes: 8 additions & 8 deletions test/commands/force/package/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { testSetup } from '@salesforce/core/lib/testSetup';
import { fromStub, stubInterface, stubMethod } from '@salesforce/ts-sinon';
import { Config } from '@oclif/core';
import { expect } from 'chai';
import { Package } from '@salesforce/packaging';
import { Package, PackageEvents } from '@salesforce/packaging';
import { Result } from '@salesforce/command';
import { Install } from '../../../../src/commands/force/package/beta/install';

Expand Down Expand Up @@ -281,7 +281,7 @@ describe('force:package:install', () => {
it('should listen for PackageInstallRequest:warning events and log warnings', async () => {
const warningMsg = 'test warning message';
installStub.callsFake(async () => {
await Lifecycle.getInstance().emit('PackageInstallRequest:warning', warningMsg);
await Lifecycle.getInstance().emit(PackageEvents.install.warning, warningMsg);
return pkgInstallRequest;
});

Expand All @@ -294,11 +294,11 @@ describe('force:package:install', () => {
expect(result).to.deep.equal(pkgInstallRequest);
});

it('should listen for PackageInstallRequest:status polling events and log statuses', async () => {
it('should listen for Package/install-status polling events and log statuses', async () => {
const successRequest = Object.assign({}, pkgInstallRequest, { Status: 'SUCCESS' });
installStub.callsFake(async () => {
await Lifecycle.getInstance().emit('PackageInstallRequest:status', pkgInstallRequest);
await Lifecycle.getInstance().emit('PackageInstallRequest:status', successRequest);
await Lifecycle.getInstance().emit(PackageEvents.install.status, pkgInstallRequest);
await Lifecycle.getInstance().emit(PackageEvents.install.status, successRequest);
return pkgInstallRequest;
});

Expand Down Expand Up @@ -443,10 +443,10 @@ describe('force:package:install', () => {
});

describe('wait for publish', () => {
it('should listen for SubscriberPackageVersion:status polling events and log statuses', async () => {
it('should listen for Package/install-subscriber-status polling events and log statuses', async () => {
waitForPublishStub.callsFake(async () => {
await Lifecycle.getInstance().emit('SubscriberPackageVersion:status', 'PACKAGE_UNAVAILABLE');
await Lifecycle.getInstance().emit('SubscriberPackageVersion:status', 'NO_ERRORS_DETECTED');
await Lifecycle.getInstance().emit(PackageEvents.install['subscriber-status'], 'PACKAGE_UNAVAILABLE');
await Lifecycle.getInstance().emit(PackageEvents.install['subscriber-status'], 'NO_ERRORS_DETECTED');
});
installStub.resolves(pkgInstallRequest);

Expand Down
6 changes: 3 additions & 3 deletions test/commands/force/package/packageCreateAndDelete.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ describe('package create/update/delete', () => {
it('should create a package - human readable results', function () {
const command = `force:package:beta:create -n ${pkgName} -v ${devHubUsernameOrAlias} -t Unlocked -r ./force-app`;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout as string;
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;
expect(output).to.contain('=== Ids');
expect(output).to.match(/Package Id\s+?0Ho/);
});
it('should update a package - human readable results', function () {
const command = `force:package:beta:update --package ${pkgName} --description "My new description" -v ${devHubUsernameOrAlias}`;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout as string;
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;
expect(output).to.match(/Successfully updated the package\.\s+0Ho/);
});
it('should delete a package - human readable results', function () {
const command = `force:package:beta:delete -p ${pkgName} -v ${devHubUsernameOrAlias} --noprompt`;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout as string;
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;
expect(output).to.contain('Successfully deleted the package. 0Ho');
});
});
Expand Down
37 changes: 18 additions & 19 deletions test/commands/force/package/packageInstalledList.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,30 @@ import { OrgConfigProperties } from '@salesforce/core';
import { expect } from 'chai';
import { PackageInstalledListResult } from '../../../../src/commands/force/package/beta/installed/list';

let session: TestSession;
let usernameOrAlias: string;

// TODO: na40 required as DevHub
before(async () => {
const executablePath = path.join(process.cwd(), 'bin', 'dev');
session = await TestSession.create({
setupCommands: [`${executablePath} config:get ${OrgConfigProperties.TARGET_DEV_HUB} --json`],
project: { name: 'packageInstalledList' },
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
usernameOrAlias = (session.setup[0] as { result: [{ value: string }] }).result[0].value;
describe('package:installed:list', () => {
let session: TestSession;
let usernameOrAlias: string;

if (!usernameOrAlias) throw Error('no default username set');
});
// TODO: na40 required as DevHub
before(async () => {
const executablePath = path.join(process.cwd(), 'bin', 'dev');
session = await TestSession.create({
setupCommands: [`${executablePath} config:get ${OrgConfigProperties.TARGET_DEV_HUB} --json`],
project: { name: 'packageInstalledList' },
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
usernameOrAlias = (session.setup[0] as { result: [{ value: string }] }).result[0].value;

after(async () => {
await session?.clean();
});
if (!usernameOrAlias) throw Error('no default username set');
});

describe('package:installed:list', () => {
after(async () => {
await session?.clean();
});
it('should list all installed packages in dev hub - human readable results', () => {
const command = `force:package:beta:installed:list -u ${usernameOrAlias}`;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout as string;
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;
expect(output).to.match(
/ID\s+?Package ID\s+?Package Name\s+?Namespace\s+?Package Version ID\s+?Version Name\s+?Version/
);
Expand Down
4 changes: 2 additions & 2 deletions test/commands/force/package/packageList.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ describe('package list', () => {
it('should list packages in dev hub - human readable results', function () {
const command = `force:package:beta:list -v ${usernameOrAlias}`;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout as string;
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;
expect(output).to.contain('=== Packages');
expect(output).to.match(/Namespace Prefix\s+?Name\s+?Id\s+?Alias\s+?Description\s+?Type/);
});
it('should list packages in dev hub - verbose human readable results', function () {
const command = `force:package:beta:list -v ${usernameOrAlias} --verbose`;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout as string;
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;
expect(output).to.contain('=== Packages');
expect(output).to.match(
/Namespace Prefix\s+?Name\s+?Id\s+?Alias\s+?Description\s+?Type\s+?Subscriber Package Id\s+?Converted From Package Id\s+?Org-Dependent Unlocked Package\s+?Error Notification Username\s+?Created By/
Expand Down
Loading

0 comments on commit a9814ab

Please sign in to comment.