Skip to content

Commit 582d64a

Browse files
committed
fix: make 1gp package version create tests more resilient
1 parent dfe9468 commit 582d64a

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

test/commands/package1/versionCreate.nut.ts

+28-15
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,39 @@ describe('package1:version:create', () => {
8181
it(`should create a new 1gp package version for package id ${packageId} without waiting`, async () => {
8282
const command = `package1:version:create -n 1gpPackageNUT -i ${packageId} -o 1gp`;
8383
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;
84-
expect(output).to.match(/PackageUploadRequest has been enqueued\./);
85-
expect(output).to.match(/package1:version:create:get -i 0HD.{15} -o/);
86-
// ensure the package has uploaded by waiting for the package report to be done
87-
// @ts-ignore
88-
uploadRequestId = /0HD\w*/.exec(output)?.at(0);
89-
await pollUntilComplete(uploadRequestId);
84+
85+
// Sometimes the package version is created faster than the test expects for a
86+
// non-waiting scenario so only verify the enqueued output.
87+
if (!output.includes('Successfully uploaded package')) {
88+
expect(output).to.match(/PackageUploadRequest has been enqueued\./);
89+
expect(output).to.match(/package1:version:create:get -i 0HD.{15} -o/);
90+
// ensure the package has uploaded by waiting for the package report to be done
91+
// @ts-ignore
92+
uploadRequestId = /0HD\w*/.exec(output)?.at(0);
93+
await pollUntilComplete(uploadRequestId);
94+
}
9095
});
9196

9297
it(`should create a new 1gp package version for package id ${packageId} (json)`, async () => {
9398
const command = `package1:version:create -n 1gpPackageNUT -i ${packageId} --json -o 1gp`;
9499
const output = execCmd<PackageUploadRequest>(command, { ensureExitCode: 0 }).jsonOutput?.result;
95-
expect(output?.Status).to.equal('QUEUED');
96-
expect(output?.Id).to.be.a('string');
97-
expect(output?.MetadataPackageId).to.be.a('string');
98-
expect(output?.MetadataPackageVersionId).to.be.a('string');
99-
expect(output?.MetadataPackageVersionId.startsWith('04t')).to.be.true;
100-
expect(output?.MetadataPackageId.startsWith('033')).to.be.true;
101-
// ensure the package has uploaded by waiting for the package report to be done
102-
// @ts-ignore
103-
await pollUntilComplete(output?.Id);
100+
101+
// Sometimes the package version is created faster than the test expects for a
102+
// non-waiting scenario so only verify the enqueued output.
103+
if (output?.Status !== 'SUCCESS') {
104+
expect(output?.Status).to.equal('QUEUED');
105+
expect(output?.Id).to.be.a('string');
106+
expect(output?.MetadataPackageId).to.be.a('string');
107+
expect(output?.MetadataPackageVersionId).to.be.a('string');
108+
expect(output?.MetadataPackageVersionId.startsWith('04t')).to.be.true;
109+
expect(output?.MetadataPackageId.startsWith('033')).to.be.true;
110+
// ensure the package has uploaded by waiting for the package report to be done
111+
// @ts-ignore
112+
await pollUntilComplete(output?.Id);
113+
}
114+
// Use this test's 0Hd if it wasn't already set by the previous test so that
115+
// tests run later won't fail.
116+
uploadRequestId ??= output?.Id ?? '';
104117
});
105118

106119
describe('package1:version:create:get', () => {

0 commit comments

Comments
 (0)