Skip to content

Commit e5bb1e2

Browse files
authored
test: run tests with vitest, fix test type errors (#1602)
* chore: fix command retry script * chore: test typefixes and update to integ test model
1 parent 23812a9 commit e5bb1e2

File tree

52 files changed

+214
-119
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+214
-119
lines changed

.changeset/rare-dancers-sparkle.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ generate-protocol-tests:
1818
test-protocols:
1919
(cd ./private/smithy-rpcv2-cbor && npx vitest run --globals)
2020

21+
test-unit:
22+
yarn g:vitest run -c vitest.config.ts
23+
24+
test-browser:
25+
yarn g:vitest run -c vitest.config.browser.ts
26+
27+
# typecheck for test code.
28+
test-types:
29+
npx tsc -p tsconfig.test.json
30+
31+
test-integration:
32+
make test-browser
33+
yarn g:vitest run -c vitest.config.integ.ts
34+
make test-types
35+
2136
turbo-clean:
2237
@read -p "Are you sure you want to delete your local cache? [y/N]: " ans && [ $${ans:-N} = y ]
2338
@echo "\nDeleted cache folders: \n--------"

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"scripts": {
88
"clean": "turbo run clean --force --parallel",
99
"build": "turbo run build",
10-
"test": "turbo run test",
11-
"test:integration": "yarn build-test-packages && turbo run test:integration",
10+
"test": "make test-unit",
11+
"test:integration": "yarn build-test-packages && make test-integration",
1212
"test:protocols": "make generate-protocol-tests test-protocols",
1313
"lint": "turbo run lint",
1414
"lint-fix": "turbo run lint -- --fix",

packages/config-resolver/src/regionConfig/isFipsRegion.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ describe(isFipsRegion.name, () => {
1212
});
1313

1414
it.each([undefined, null])("returns false for %s", (input) => {
15-
expect(isFipsRegion(input)).toEqual(false);
15+
expect(isFipsRegion(input as any)).toEqual(false);
1616
});
1717
});

packages/config-resolver/src/regionConfig/resolveRegionConfig.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ describe("RegionConfig", () => {
5454
});
5555

5656
describe("useFipsEndpoint", () => {
57-
let mockRegionProvider;
58-
let mockUseFipsEndpoint;
57+
let mockRegionProvider: () => Promise<string>;
58+
let mockUseFipsEndpoint: () => Promise<boolean>;
5959

6060
beforeEach(() => {
6161
mockRegionProvider = vi.fn().mockResolvedValueOnce(Promise.resolve(mockRegion));

packages/config-resolver/src/regionInfo/getRegionInfo.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ describe(getRegionInfo.name, () => {
5656
const getMockResolvedRegion = (regionCase: RegionCase): string =>
5757
regionCase !== RegionCase.ENDPOINT ? mockRegion : mockEndpointRegion;
5858

59-
const getMockResolvedPartitionOptions = (partitionHash) => ({ partitionHash });
59+
const getMockResolvedPartitionOptions = (partitionHash: PartitionHash) => ({ partitionHash });
6060

61-
const getMockRegionInfoOptions = (regionHash, getResolvedPartitionOptions) => ({
61+
const getMockRegionInfoOptions = (regionHash: RegionHash, getResolvedPartitionOptions: any) => ({
6262
...getResolvedPartitionOptions,
6363
signingService: mockSigningService,
6464
regionHash,

packages/config-resolver/src/regionInfo/getResolvedPartition.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ describe(getResolvedPartition.name, () => {
3232
});
3333

3434
it("returns aws if partitionHash is empty", () => {
35-
expect(getResolvedPartition(mockRegion, { partitionHash: undefined })).toBe("aws");
35+
expect(getResolvedPartition(mockRegion, { partitionHash: undefined as any })).toBe("aws");
3636
});
3737
});

packages/core/src/submodules/cbor/cbor.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as fs from "fs";
2+
// @ts-ignore
23
import JSONbig from "json-bigint";
34
import * as path from "path";
45
import { describe, expect, test as it } from "vitest";
@@ -290,7 +291,7 @@ describe("cbor", () => {
290291
return scalar * sum * exponentScalar;
291292
}
292293

293-
function translateTestData(data: any) {
294+
function translateTestData(data: any): any {
294295
const [type, value] = Object.entries(data)[0] as [string, any];
295296
switch (type) {
296297
case "null":

packages/core/src/submodules/schema/middleware/schemaDeserializationMiddleware.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe(schemaDeserializationMiddleware.name, () => {
8585
expect(mockNext).toHaveBeenCalledWith(mockArgs);
8686
expect(mockDeserializer).toHaveBeenCalledTimes(1);
8787
expect(mockDeserializer).toHaveBeenCalledWith(
88-
undefined as SchemaRef,
88+
undefined as any as SchemaRef,
8989
{
9090
...mockOptions,
9191
__smithy_context: {},

packages/core/src/submodules/schema/middleware/schemaSerializationMiddleware.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe(schemaSerializationMiddleware.name, () => {
5959
await expect(schemaSerializationMiddleware(mockOptions)(mockNext, {})(mockArgs)).resolves.toStrictEqual(mockReturn);
6060

6161
expect(mockSerializer).toHaveBeenCalledTimes(1);
62-
expect(mockSerializer).toHaveBeenCalledWith(undefined as SchemaRef, mockArgs.input, {
62+
expect(mockSerializer).toHaveBeenCalledWith(undefined as unknown as SchemaRef, mockArgs.input, {
6363
...mockOptions,
6464
__smithy_context: {},
6565
});

packages/credential-provider-imds/src/remoteProvider/httpRequest.spec.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import EventEmitter from "events";
2020
import { request } from "http";
2121

2222
describe("httpRequest", () => {
23-
let port: number;
2423
const hostname = "localhost";
2524
const path = "/";
2625

@@ -53,7 +52,7 @@ describe("httpRequest", () => {
5352

5453
mockResponse({ expectedResponse });
5554

56-
const response = await httpRequest({ hostname, path, port });
55+
const response = await httpRequest({ hostname, path });
5756
expect(response.toString()).toStrictEqual(expectedResponse);
5857
});
5958

@@ -62,7 +61,7 @@ describe("httpRequest", () => {
6261
const expectedResponse = "expectedResponse";
6362
mockResponse({ expectedResponse });
6463

65-
const response = await httpRequest({ hostname, path, port, method });
64+
const response = await httpRequest({ hostname, path, method });
6665
expect(response.toString()).toStrictEqual(expectedResponse);
6766
});
6867

@@ -71,7 +70,7 @@ describe("httpRequest", () => {
7170
const encapsulatedIPv6Hostname = "[::1]";
7271
mockResponse({ expectedResponse });
7372

74-
const response = await httpRequest({ hostname: encapsulatedIPv6Hostname, path, port });
73+
const response = await httpRequest({ hostname: encapsulatedIPv6Hostname, path });
7574
expect(response.toString()).toStrictEqual(expectedResponse);
7675
});
7776
});
@@ -84,7 +83,7 @@ describe("httpRequest", () => {
8483
expectedResponse: "continue",
8584
});
8685

87-
await expect(httpRequest({ hostname, path, port })).rejects.toStrictEqual(
86+
await expect(httpRequest({ hostname, path })).rejects.toStrictEqual(
8887
Object.assign(new ProviderError("Error response received from instance metadata service"), { statusCode })
8988
);
9089
});
@@ -102,7 +101,7 @@ describe("httpRequest", () => {
102101
return request;
103102
}) as any);
104103

105-
await expect(httpRequest({ hostname, path, port })).rejects.toStrictEqual(
104+
await expect(httpRequest({ hostname, path })).rejects.toStrictEqual(
106105
new ProviderError("Unable to connect to instance metadata service")
107106
);
108107
});
@@ -131,7 +130,7 @@ describe("httpRequest", () => {
131130
return request;
132131
}) as any);
133132

134-
await expect(httpRequest({ hostname, path, port, timeout })).rejects.toStrictEqual(
133+
await expect(httpRequest({ hostname, path, timeout })).rejects.toStrictEqual(
135134
new ProviderError("TimeoutError from instance metadata service")
136135
);
137136
});

packages/credential-provider-imds/src/utils/getInstanceMetadataEndpoint.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ vi.mock("@smithy/url-parser");
1313

1414
describe(getInstanceMetadataEndpoint.name, () => {
1515
let mockURL: string;
16-
const mockEndpoint = { protocol: "http:", hostname: "localhost", port: "80" };
16+
const mockEndpoint = { protocol: "http:", hostname: "localhost", port: 80, path: "" };
1717

1818
beforeEach(() => {
1919
vi.mocked(parseUrl).mockReturnValue(mockEndpoint);

packages/credential-provider-imds/src/utils/staticStabilityProvider.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe("staticStabilityProvider", () => {
2424
return {
2525
...input,
2626
expiration: `Extending expiration count: ${extensionCount}`,
27-
};
27+
} as any;
2828
};
2929
})()
3030
);

packages/hash-blob-browser/src/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe("blobHasher", () => {
77
const blob = new Blob(["test-string"]);
88

99
class Hash {
10-
public value: string;
10+
public value: string = "";
1111
update(value: string) {
1212
this.value = value;
1313
}

packages/hash-stream-node/src/readableStreamHasher.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ describe(readableStreamHasher.name, () => {
2222
class MockHashCalculator extends Writable {
2323
constructor(
2424
public readonly hash: Hash,
25-
public readonly mockWrite,
26-
public readonly mockEnd
25+
public readonly mockWrite: any,
26+
public readonly mockEnd: any
2727
) {
2828
super();
2929
}
@@ -41,7 +41,7 @@ describe(readableStreamHasher.name, () => {
4141

4242
beforeEach(() => {
4343
(HashCalculator as unknown as any).mockImplementation(
44-
(hash) => new MockHashCalculator(hash, mockHashCalculatorWrite, mockHashCalculatorEnd)
44+
(hash: Hash) => new MockHashCalculator(hash, mockHashCalculatorWrite, mockHashCalculatorEnd)
4545
);
4646
mockDigest.mockResolvedValue(mockHash);
4747
});

packages/middleware-compression/src/compressStream.browser.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe(compressStream.name, () => {
1616
const data = typeof chunk === "string" ? [chunk, compressionSuffix].join(compressionSeparator) : null;
1717
asyncGzip.ondata(undefined, data, final);
1818
}),
19+
terminate() {}
1920
};
2021

2122
beforeEach(() => {

packages/middleware-compression/src/compressStream.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe(compressStream.name, () => {
2020
const testOutputStream = Readable.from(getGenerator(["input", "gzipped"])());
2121

2222
beforeEach(() => {
23-
(vi.mocked(createGzip)).mockReturnValue(mockGzipFn);
23+
(vi.mocked(createGzip)).mockReturnValue(mockGzipFn as any);
2424
testInputStream.pipe = vi.fn().mockReturnValue(testOutputStream);
2525
});
2626

packages/middleware-compression/src/compressString.browser.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ describe(compressString.name, () => {
1414
const compressionSeparator = ".";
1515

1616
beforeEach(() => {
17-
(vi.mocked(toUint8Array)).mockImplementation((data) => data);
17+
vi.mocked(toUint8Array).mockImplementation((data) => data as any);
1818
});
1919

2020
afterEach(() => {
2121
vi.clearAllMocks();
2222
});
2323

2424
it("should compress data with gzip", async () => {
25-
(vi.mocked(gzip)).mockImplementation((data, callback) => {
25+
vi.mocked(gzip).mockImplementation(((data: any, callback: any) => {
2626
callback(null, [data, compressionSuffix].join(compressionSeparator));
27-
});
27+
}) as any);
2828
const receivedOutput = await compressString(testData);
2929
const expectedOutput = [testData, compressionSuffix].join(compressionSeparator);
3030

@@ -38,9 +38,9 @@ describe(compressString.name, () => {
3838
it("should throw an error if compression fails", async () => {
3939
const compressionErrorMsg = "compression error message";
4040
const compressionError = new Error(compressionErrorMsg);
41-
(vi.mocked(gzip)).mockImplementation((data, callback) => {
41+
vi.mocked(gzip).mockImplementation(((data: any, callback: any) => {
4242
callback(compressionError);
43-
});
43+
}) as any);
4444

4545
await expect(compressString(testData)).rejects.toThrow(
4646
new Error("Failure during compression: " + compressionErrorMsg)

packages/middleware-compression/src/compressString.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe(compressString.name, () => {
1818
const testData = "test";
1919

2020
beforeEach(() => {
21-
(vi.mocked(toUint8Array)).mockImplementation((data) => data);
21+
(vi.mocked(toUint8Array)).mockImplementation((data: any) => data);
2222
});
2323

2424
afterEach(() => {

packages/middleware-compression/src/compressionMiddleware.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe(compressionMiddleware.name, () => {
8383
});
8484

8585
it("compresses streaming blob", async () => {
86-
const mockCompressedStream = "compressed-stream";
86+
const mockCompressedStream = "compressed-stream" as any;
8787
(vi.mocked(compressStream)).mockResolvedValueOnce(mockCompressedStream);
8888

8989
await compressionMiddleware(mockConfig, mockMiddlewareConfig)(mockNext, mockContext)({ ...mockArgs } as any);
@@ -120,7 +120,7 @@ describe(compressionMiddleware.name, () => {
120120
});
121121

122122
it("compresses body", async () => {
123-
const mockCompressedBody = "compressed-body";
123+
const mockCompressedBody = "compressed-body" as any;
124124
(vi.mocked(compressString)).mockResolvedValueOnce(mockCompressedBody);
125125

126126
await compressionMiddleware(mockConfig, mockMiddlewareConfig)(mockNext, mockContext)({ ...mockArgs } as any);
@@ -141,7 +141,7 @@ describe(compressionMiddleware.name, () => {
141141
});
142142

143143
it("appends algorithm to existing Content-Encoding header", async () => {
144-
const mockCompressedBody = "compressed-body";
144+
const mockCompressedBody = "compressed-body" as any;
145145
(vi.mocked(compressString)).mockResolvedValueOnce(mockCompressedBody);
146146

147147
const mockExistingContentEncoding = "deflate";

packages/middleware-compression/src/getCompressionPlugin.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe(getCompressionPlugin.name, () => {
1414
const middlewareConfig = { encodings: [] };
1515

1616
it("applyToStack adds compressionMiddleware", () => {
17-
const middlewareReturn = {};
17+
const middlewareReturn = {} as any;
1818
(vi.mocked(compressionMiddleware)).mockReturnValueOnce(middlewareReturn);
1919

2020
const plugin = getCompressionPlugin(config, middlewareConfig);

packages/middleware-retry/src/AdaptiveRetryStrategy.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe(AdaptiveRetryStrategy.name, () => {
1313
const mockDefaultRateLimiter = {
1414
getSendToken: vi.fn(),
1515
updateClientSendingRate: vi.fn(),
16-
};
16+
} as any;
1717

1818
beforeEach(() => {
1919
vi.mocked(DefaultRateLimiter).mockReturnValue(mockDefaultRateLimiter);
@@ -85,13 +85,13 @@ describe(AdaptiveRetryStrategy.name, () => {
8585

8686
it("calls rateLimiter.getSendToken in beforeRequest", async () => {
8787
expect(mockDefaultRateLimiter.getSendToken).toHaveBeenCalledTimes(0);
88-
await mockedSuperRetry.mock.calls[0][2].beforeRequest();
88+
await mockedSuperRetry.mock.calls[0][2]!.beforeRequest();
8989
expect(mockDefaultRateLimiter.getSendToken).toHaveBeenCalledTimes(1);
9090
});
9191

9292
it("calls rateLimiter.updateClientSendingRate in afterRequest", async () => {
9393
expect(mockDefaultRateLimiter.updateClientSendingRate).toHaveBeenCalledTimes(0);
94-
await mockedSuperRetry.mock.calls[0][2].afterRequest();
94+
await mockedSuperRetry.mock.calls[0][2]!.afterRequest();
9595
expect(mockDefaultRateLimiter.updateClientSendingRate).toHaveBeenCalledTimes(1);
9696
});
9797
});

packages/node-config-provider/src/configLoader.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ describe("loadConfig", () => {
2020
});
2121

2222
it("passes fromEnv(), fromSharedConfigFiles() and fromStatic() to chain", () => {
23-
const mockFromEnvReturn = "mockFromEnvReturn";
23+
const mockFromEnvReturn = "mockFromEnvReturn" as any;
2424
vi.mocked(fromEnv).mockReturnValueOnce(mockFromEnvReturn);
25-
const mockFromSharedConfigFilesReturn = "mockFromSharedConfigFilesReturn";
25+
const mockFromSharedConfigFilesReturn = "mockFromSharedConfigFilesReturn" as any;
2626
vi.mocked(fromSharedConfigFiles).mockReturnValueOnce(mockFromSharedConfigFilesReturn);
27-
const mockFromStatic = "mockFromStatic";
27+
const mockFromStatic = "mockFromStatic" as any;
2828
vi.mocked(fromStatic).mockReturnValueOnce(mockFromStatic);
2929
// Using Record<string, string | undefined> instead of NodeJS.ProcessEnv, in order to not get type errors in non node environments
3030
const envVarSelector = (env: Record<string, string | undefined>) => env["AWS_CONFIG_FOO"];
@@ -49,7 +49,7 @@ describe("loadConfig", () => {
4949
});
5050

5151
it("passes output of chain to memoize", () => {
52-
const mockChainReturn = "mockChainReturn";
52+
const mockChainReturn = "mockChainReturn" as any;
5353
vi.mocked(chain).mockReturnValueOnce(mockChainReturn);
5454
loadConfig({} as any);
5555
expect(chain).toHaveBeenCalledTimes(1);
@@ -58,7 +58,7 @@ describe("loadConfig", () => {
5858
});
5959

6060
it("returns output memoize", () => {
61-
const mockMemoizeReturn = "mockMemoizeReturn";
61+
const mockMemoizeReturn = "mockMemoizeReturn" as any;
6262
vi.mocked(memoize).mockReturnValueOnce(mockMemoizeReturn);
6363
expect(loadConfig({} as any)).toEqual(mockMemoizeReturn);
6464
});

packages/node-config-provider/src/fromSharedConfigFiles.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ describe("fromSharedConfigFiles", () => {
165165
it.each(["foo", "default"])("returns config value from %s profile", (profile) => {
166166
vi.mocked(getProfileName).mockReturnValueOnce(profile);
167167
return expect(fromSharedConfigFiles(configGetter)()).resolves.toBe(
168-
loadedConfigData.configFile[profile][CONFIG_KEY]
168+
(loadedConfigData.configFile as Record<string, { config_key: string }>)[profile][CONFIG_KEY]
169169
);
170170
});
171171
});

packages/node-config-provider/src/fromStatic.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ vi.mock("@smithy/property-provider", () => ({
88
}));
99

1010
describe("fromStatic", () => {
11-
const value = "default";
11+
const value = "default" as any;
1212
it("should convert static values to provider", async () => {
1313
vi.mocked(convertToProvider).mockReturnValue(value);
1414
fromStatic(value);

0 commit comments

Comments
 (0)