Skip to content

Commit

Permalink
chore: tests are not isolated (#181)
Browse files Browse the repository at this point in the history
The `upload external asset correctly` test was asserting that
`PutObject` would be called twice, but it was only called twice because
a test run prior to it leaked a `PubObject` invocation that was counted
towards the count of this test.

If the test was run by itself, the `PutObject` count was `1`, not `2`,
and the test would fail.

Also remove a log statement that breaks the linter in the new repo.
  • Loading branch information
rix0rrr authored Nov 12, 2024
1 parent 4dd9a18 commit 33027b3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
15 changes: 5 additions & 10 deletions lib/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,11 @@ export class DefaultAwsClient implements IAws {
listObjectsV2: (input: ListObjectsV2CommandInput): Promise<ListObjectsV2CommandOutput> =>
client.send(new ListObjectsV2Command(input)),
upload: (input: PutObjectCommandInput): Promise<CompleteMultipartUploadCommandOutput> => {
try {
const upload = new Upload({
client,
params: input,
});
return upload.done();
} catch (e: any) {
console.log(`Asset upload failed: '${e.message}'`);
throw e;
}
const upload = new Upload({
client,
params: input,
});
return upload.done();
},
};
}
Expand Down
8 changes: 4 additions & 4 deletions test/files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ test('correctly identify asset path if path is absolute', async () => {
const pub = new AssetPublishing(AssetManifest.fromPath(mockfs.path('/abs/cdk.out')), { aws });
s3.on(ListObjectsV2Command).resolves({ Contents: undefined });

expect(async () => {
await pub.publish();
}).not.toThrow();
await pub.publish();

// THEN: doesn't throw
});

describe('external assets', () => {
Expand Down Expand Up @@ -365,7 +365,7 @@ describe('external assets', () => {

await pub.publish();

expect(s3).toHaveReceivedCommandTimes(PutObjectCommand, 2);
expect(s3).toHaveReceivedCommandTimes(PutObjectCommand, 1);

expectAllSpawns();
});
Expand Down

0 comments on commit 33027b3

Please sign in to comment.