Skip to content

Commit

Permalink
test(packages): await promise assertions, cleanup test logging (#6839)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe authored Jan 22, 2025
1 parent 84d6c18 commit e504341
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions clients/client-s3/test/unit/S3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ describe("signing", () => {
return await client.putObject({
Bucket: "bucket",
Key: "some file.txt",
Body: "abcd",
});
});
});
2 changes: 1 addition & 1 deletion lib/lib-storage/src/Upload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ describe(Upload.name, () => {
});

await upload.done();
expect(() => upload.done()).rejects.toEqual(
await expect(() => upload.done()).rejects.toEqual(
new Error("@aws-sdk/lib-storage: this instance of Upload has already executed .done(). Create a new instance.")
);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/dsql-signer/src/runtimeConfig.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("getRuntimeConfig", () => {
hostname: "test.example.com",
};
const { credentials, region } = getRuntimeConfig(minimalParams);
expect(credentials).rejects.toEqual("Credential is missing");
expect(region).rejects.toEqual("Region is missing");
await expect(credentials).rejects.toEqual("Credential is missing");
await expect(region).rejects.toEqual("Region is missing");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ describe(EventStreamPayloadHandler.name, () => {
vi.clearAllMocks();
});

it("should throw if request payload is not a stream", () => {
it("should throw if request payload is not a stream", async () => {
const handler = new EventStreamPayloadHandler({
messageSigner: () => Promise.resolve(mockMessageSigner),
utf8Decoder: mockUtf8Decoder,
utf8Encoder: mockUtf8encoder,
});
expect(
await expect(
handler.handle(mockNextHandler, {
request: { body: "body" } as HttpRequest,
input: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ describe(resolveEndpointDiscoveryConfig.name, () => {
});

describe("endpointDiscoveryEnabled", () => {
it.each<boolean>([false, true])(`sets to value passed in the config: %s`, (endpointDiscoveryEnabled) => {
it.each<boolean>([false, true])(`sets to value passed in the config: %s`, async (endpointDiscoveryEnabled) => {
const resolvedConfig = resolveEndpointDiscoveryConfig(
{
...mockInput,
endpointDiscoveryEnabled,
},
{ endpointDiscoveryCommandCtor }
);
expect(resolvedConfig.endpointDiscoveryEnabled()).resolves.toBe(endpointDiscoveryEnabled);
await expect(resolvedConfig.endpointDiscoveryEnabled()).resolves.toBe(endpointDiscoveryEnabled);
expect(mockInput.endpointDiscoveryEnabledProvider).not.toHaveBeenCalled();
expect(resolvedConfig.isClientEndpointDiscoveryEnabled).toStrictEqual(true);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("checkContentLengthHeaderMiddleware", () => {
let spy: any;

beforeEach(() => {
spy = vi.spyOn(console, "warn");
spy = vi.spyOn(console, "warn").mockImplementation(() => {});
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe(normalizeTokenProvider.name, () => {
it("returns memoized function", async () => {
const normalizedTokenProvider = normalizeTokenProvider(mockInputToken);
expect(normalizedTokenProvider).toEqual(mockMemoizeFn);
expect(mockMemoizeFn()).resolves.toEqual(mockToken);
await expect(mockMemoizeFn()).resolves.toEqual(mockToken);
});

describe("memoize isExpired", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ describe(EventStreamPayloadHandler.name, () => {
vi.clearAllMocks();
});

it("should throw if request payload is not a stream", () => {
it("should throw if request payload is not a stream", async () => {
const handler = new EventStreamPayloadHandler({
messageSigner: () => Promise.resolve(mockSigner),
utf8Decoder: mockUtf8Decoder,
utf8Encoder: mockUtf8encoder,
});
expect(
await expect(
handler.handle(mockNextHandler, {
request: { body: "body" } as HttpRequest,
input: {},
Expand Down
4 changes: 2 additions & 2 deletions packages/rds-signer/src/runtimeConfig.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("getRuntimeConfig", () => {
port: 5432,
};
const { credentials, region } = getRuntimeConfig(minimalParams);
expect(credentials).rejects.toEqual("Credential is missing");
expect(region).rejects.toEqual("Region is missing");
await expect(credentials).rejects.toEqual("Credential is missing");
await expect(region).rejects.toEqual("Region is missing");
});
});

0 comments on commit e504341

Please sign in to comment.