Skip to content

Commit 073cb75

Browse files
authored
test(packages): convert to vitest (#6588)
* test(packages): convert to vitest * test: remove karma
1 parent 38debde commit 073cb75

File tree

124 files changed

+672
-531
lines changed

Some content is hidden

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

124 files changed

+672
-531
lines changed

lib/lib-storage/karma.conf.js

-30
This file was deleted.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"lint:versions": "node scripts/runtime-dependency-version-check/runtime-dep-version-check.js",
3333
"lint:dependencies": "node scripts/runtime-dependency-version-check/check-dependencies.js",
3434
"local-publish": "node ./scripts/verdaccio-publish/index.js",
35-
"test:all": "yarn build:all && jest --coverage --passWithNoTests && lerna run test --scope '@aws-sdk/{fetch-http-handler,hash-blob-browser}' && yarn test:versions && yarn test:integration",
35+
"test:all": "yarn build:all && jest --passWithNoTests && lerna run test --scope '@aws-sdk/{fetch-http-handler,hash-blob-browser}' && yarn test:versions && yarn test:integration",
3636
"test:ci": "lerna run test --since origin/main",
3737
"test:e2e": "node ./scripts/turbo test:e2e && node ./tests/canary/canary",
3838
"test:e2e:legacy": "cucumber-js --fail-fast",

packages/middleware-eventstream/jest.config.js

-5
This file was deleted.

packages/middleware-sdk-sts/jest.config.js

-5
This file was deleted.

packages/polly-request-presigner/jest.config.js

-5
This file was deleted.

packages/polly-request-presigner/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
1111
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
1212
"extract:docs": "api-extractor run --local",
13-
"test": "jest"
13+
"test": "vitest run",
14+
"test:watch": "vitest watch"
1415
},
1516
"main": "./dist-cjs/index.js",
1617
"module": "./dist-es/index.js",

packages/polly-request-presigner/src/getSignedUrls.spec.ts

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
const mockV4Sign = jest.fn();
2-
const mockPresign = jest.fn();
3-
const mockV4 = jest.fn().mockReturnValue({
4-
presign: mockPresign,
5-
sign: mockV4Sign,
6-
});
7-
jest.mock("@smithy/signature-v4", () => ({
8-
SignatureV4: mockV4,
9-
}));
1+
import { beforeEach, describe, expect, test as it, vi } from "vitest";
102

3+
vi.mock("@smithy/signature-v4", () => ({
4+
SignatureV4: vi.fn().mockReturnValue({
5+
presign: vi.fn(),
6+
sign: vi.fn(),
7+
}),
8+
}));
119
import { PollyClient, SynthesizeSpeechCommand } from "@aws-sdk/client-polly";
10+
import { SignatureV4 } from "@smithy/signature-v4";
1211

13-
jest.mock("@aws-sdk/util-format-url", () => ({
12+
vi.mock("@aws-sdk/util-format-url", () => ({
1413
formatUrl: (url: any) => url,
1514
}));
1615

@@ -19,6 +18,7 @@ import { AwsCredentialIdentity, RequestPresigningArguments } from "@smithy/types
1918
import { getSignedUrl } from "./getSignedUrls";
2019

2120
describe("getSignedUrl", () => {
21+
const mockInstance = new SignatureV4({} as any);
2222
const credentials: AwsCredentialIdentity = {
2323
secretAccessKey: "unit-test",
2424
accessKeyId: "unit-test",
@@ -27,12 +27,12 @@ describe("getSignedUrl", () => {
2727
const clientParams = { region: "us-foo-1", credentials };
2828

2929
beforeEach(() => {
30-
mockPresign.mockReset();
30+
vi.mocked(mockInstance).presign.mockReset();
3131
});
3232

3333
it("should call SignatureV4.sign", async () => {
3434
const mockPresigned = "a presigned url";
35-
mockPresign.mockReturnValue(mockPresigned);
35+
vi.mocked(mockInstance).presign.mockReturnValue(mockPresigned as any);
3636
const client = new PollyClient(clientParams);
3737
const command = new SynthesizeSpeechCommand({
3838
Text: "hello world, this is alex",
@@ -41,15 +41,15 @@ describe("getSignedUrl", () => {
4141
});
4242
const signed = await getSignedUrl(client, command);
4343
expect(signed).toBe(mockPresigned);
44-
expect(mockPresign).toBeCalled();
45-
expect(mockV4Sign).not.toBeCalled();
44+
expect(vi.mocked(mockInstance).presign).toBeCalled();
45+
expect(vi.mocked(mockInstance).sign).not.toBeCalled();
4646
expect(client.middlewareStack.remove("presignInterceptMiddleware")).toBe(false);
4747
expect(command.middlewareStack.remove("presignInterceptMiddleware")).toBe(false);
4848
});
4949

5050
it("should presign with signing region and service in context if exists", async () => {
5151
const mockPresigned = "a presigned url";
52-
mockPresign.mockReturnValue(mockPresigned);
52+
vi.mocked(mockInstance).presign.mockReturnValue(mockPresigned as any);
5353
const signingRegion = "aws-foo-1";
5454
const signingService = "bar";
5555
const client = new PollyClient(clientParams);
@@ -70,16 +70,16 @@ describe("getSignedUrl", () => {
7070
VoiceId: "Kimberly",
7171
});
7272
await getSignedUrl(client, command);
73-
expect(mockPresign).toBeCalled();
74-
expect(mockPresign.mock.calls[0][1]).toMatchObject({
73+
expect(vi.mocked(mockInstance).presign).toBeCalled();
74+
expect(vi.mocked(mockInstance).presign.mock.calls[0][1]).toMatchObject({
7575
signingRegion,
7676
signingService,
7777
});
7878
});
7979

8080
it("should presign with parameters from presign options if set", async () => {
8181
const mockPresigned = "a presigned url";
82-
mockPresign.mockReturnValue(mockPresigned);
82+
vi.mocked(mockInstance).presign.mockReturnValue(mockPresigned as any);
8383
const options: RequestPresigningArguments = {
8484
signingRegion: "aws-foo-1",
8585
signingService: "bar",
@@ -95,12 +95,12 @@ describe("getSignedUrl", () => {
9595
VoiceId: "Kimberly",
9696
});
9797
await getSignedUrl(client, command, options);
98-
expect(mockPresign).toBeCalled();
99-
expect(mockPresign.mock.calls[0][1]).toMatchObject(options);
98+
expect(vi.mocked(mockInstance).presign).toBeCalled();
99+
expect(vi.mocked(mockInstance).presign.mock.calls[0][1]).toMatchObject(options);
100100
});
101101
it("should not throw if called concurrently", async () => {
102102
const mockPresigned = "a presigned url";
103-
mockPresign.mockReturnValue(mockPresigned);
103+
vi.mocked(mockInstance).presign.mockReturnValue(mockPresigned as any);
104104
const client = new PollyClient(clientParams);
105105
const command = new SynthesizeSpeechCommand({
106106
Text: "hello world, this is alex",
@@ -110,6 +110,6 @@ describe("getSignedUrl", () => {
110110
const result = await Promise.all([getSignedUrl(client, command), getSignedUrl(client, command)]);
111111
expect(result).toBeInstanceOf(Array);
112112
expect(result).toHaveLength(2);
113-
expect(mockPresign).toHaveBeenCalledTimes(2);
113+
expect(vi.mocked(mockInstance).presign).toHaveBeenCalledTimes(2);
114114
});
115115
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
exclude: ["**/*.{integ,e2e,browser}.spec.ts"],
6+
include: ["**/*.spec.ts"],
7+
environment: "node",
8+
},
9+
});

packages/rds-signer/jest.config.js

-5
This file was deleted.

packages/rds-signer/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
1515
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
1616
"extract:docs": "api-extractor run --local",
17-
"test": "jest"
17+
"test": "vitest run",
18+
"test:watch": "vitest watch"
1819
},
1920
"engines": {
2021
"node": ">=16.0.0"

packages/rds-signer/src/Signer.spec.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@ import { formatUrl } from "@aws-sdk/util-format-url";
33
import { loadConfig } from "@smithy/node-config-provider";
44
import { HttpRequest } from "@smithy/protocol-http";
55
import { SignatureV4 } from "@smithy/signature-v4";
6+
import { beforeAll, beforeEach, describe, expect, test as it, vi } from "vitest";
67

78
import { Signer, SignerConfig } from "./Signer";
89

9-
const mockPresign = jest.fn();
10-
jest.mock("@smithy/signature-v4", () => {
10+
const mockPresign = vi.fn();
11+
vi.mock("@smithy/signature-v4", () => {
1112
return {
12-
SignatureV4: jest.fn().mockImplementation(() => {
13+
SignatureV4: vi.fn().mockImplementation(() => {
1314
return { presign: mockPresign };
1415
}),
1516
};
1617
});
1718

18-
jest.mock("@smithy/node-config-provider");
19-
jest.mock("@smithy/config-resolver");
20-
jest.mock("@aws-sdk/credential-providers");
21-
jest.mock("@aws-sdk/util-format-url");
19+
vi.mock("@smithy/node-config-provider");
20+
vi.mock("@smithy/config-resolver");
21+
vi.mock("@aws-sdk/credential-providers");
22+
vi.mock("@aws-sdk/util-format-url");
2223

2324
describe("rds-signer", () => {
2425
const minimalParams: SignerConfig = {
@@ -28,20 +29,20 @@ describe("rds-signer", () => {
2829
};
2930

3031
beforeAll(() => {
31-
(formatUrl as jest.Mock).mockReturnValue("https://testhost:5432?other=url&parameters=here");
32+
vi.mocked(formatUrl).mockReturnValue("https://testhost:5432?other=url&parameters=here");
3233
});
3334

3435
beforeEach(() => {
35-
jest.clearAllMocks();
36+
vi.clearAllMocks();
3637
});
3738

3839
it("should provide correct parameters to the SigV4 signer", async () => {
3940
const credentials = {
4041
accessKeyId: "xyz",
4142
secretAccessKey: "123",
4243
};
43-
(loadConfig as jest.Mock).mockReturnValue(async () => "us-foo-1");
44-
(fromNodeProviderChain as jest.Mock).mockReturnValue(async () => credentials);
44+
vi.mocked(loadConfig).mockReturnValue(async () => "us-foo-1");
45+
vi.mocked(fromNodeProviderChain).mockReturnValue(async () => credentials);
4546
const signer = new Signer(minimalParams);
4647
await signer.getAuthToken();
4748
//@ts-ignore

packages/rds-signer/src/index.spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, test as it } from "vitest";
2+
13
import * as rdsSigner from "./index";
24

35
describe("rds-signer", () => {

packages/rds-signer/src/runtimeConfig.spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, test as it } from "vitest";
2+
13
import { getRuntimeConfig as getBrowserRuntimeConfig } from "./runtimeConfig.browser";
24
import { getRuntimeConfig as getRnRuntimeConfig } from "./runtimeConfig.native";
35
import { SignerConfig } from "./Signer";

packages/rds-signer/vitest.config.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
exclude: ["**/*.{integ,e2e,browser}.spec.ts"],
6+
include: ["**/*.spec.ts"],
7+
environment: "node",
8+
},
9+
});

packages/region-config-resolver/jest.config.js

-5
This file was deleted.

packages/region-config-resolver/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
1111
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
1212
"extract:docs": "api-extractor run --local",
13-
"test": "jest"
13+
"test": "vitest run",
14+
"test:watch": "vitest watch"
1415
},
1516
"main": "./dist-cjs/index.js",
1617
"module": "./dist-es/index.js",

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

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, test as it } from "vitest";
2+
13
import {
24
NODE_REGION_CONFIG_FILE_OPTIONS,
35
NODE_REGION_CONFIG_OPTIONS,

packages/region-config-resolver/src/regionConfig/getRealRegion.spec.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1+
import { afterEach, beforeEach, describe, expect, test as it, vi } from "vitest";
2+
13
import { getRealRegion } from "./getRealRegion";
24
import { isFipsRegion } from "./isFipsRegion";
35

4-
jest.mock("./isFipsRegion");
6+
vi.mock("./isFipsRegion");
57

68
describe(getRealRegion.name, () => {
79
beforeEach(() => {
8-
(isFipsRegion as jest.Mock).mockReturnValue(true);
10+
vi.mocked(isFipsRegion).mockReturnValue(true);
911
});
1012

1113
afterEach(() => {
1214
expect(isFipsRegion).toHaveBeenCalledTimes(1);
13-
jest.clearAllMocks();
15+
vi.clearAllMocks();
1416
});
1517

1618
it("returns provided region if it's not FIPS", () => {
1719
const mockRegion = "mockRegion";
18-
(isFipsRegion as jest.Mock).mockReturnValue(false);
20+
vi.mocked(isFipsRegion).mockReturnValue(false);
1921
expect(getRealRegion(mockRegion)).toStrictEqual(mockRegion);
2022
});
2123

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

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, test as it } from "vitest";
2+
13
import { isFipsRegion } from "./isFipsRegion";
24

35
describe(isFipsRegion.name, () => {

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
import { Provider } from "@smithy/types";
2+
import { afterEach, beforeEach, describe, expect, test as it, vi } from "vitest";
23

34
import { getRealRegion } from "./getRealRegion";
45
import { isFipsRegion } from "./isFipsRegion";
56
import { resolveRegionConfig } from "./resolveRegionConfig";
67

7-
jest.mock("./getRealRegion");
8-
jest.mock("./isFipsRegion");
8+
vi.mock("./getRealRegion");
9+
vi.mock("./isFipsRegion");
910

1011
describe("RegionConfig", () => {
1112
const mockRegion = "mockRegion";
1213
const mockRealRegion = "mockRealRegion";
1314
const mockUseFipsEndpoint = () => Promise.resolve(false);
1415

1516
beforeEach(() => {
16-
(getRealRegion as jest.Mock).mockReturnValue(mockRealRegion);
17-
(isFipsRegion as jest.Mock).mockReturnValue(false);
17+
vi.mocked(getRealRegion).mockReturnValue(mockRealRegion);
18+
vi.mocked(isFipsRegion).mockReturnValue(false);
1819
});
1920

2021
afterEach(() => {
21-
jest.clearAllMocks();
22+
vi.clearAllMocks();
2223
});
2324

2425
describe("region", () => {
@@ -51,8 +52,8 @@ describe("RegionConfig", () => {
5152
let mockUseFipsEndpoint: boolean | Provider<boolean>;
5253

5354
beforeEach(() => {
54-
mockRegionProvider = jest.fn().mockResolvedValueOnce(Promise.resolve(mockRegion));
55-
mockUseFipsEndpoint = jest.fn().mockResolvedValueOnce(Promise.resolve(false));
55+
mockRegionProvider = vi.fn().mockResolvedValueOnce(Promise.resolve(mockRegion));
56+
mockUseFipsEndpoint = vi.fn().mockResolvedValueOnce(Promise.resolve(false));
5657
});
5758

5859
afterEach(() => {
@@ -70,7 +71,7 @@ describe("RegionConfig", () => {
7071
});
7172

7273
it("returns Provider which returns true for FIPS endpoints", async () => {
73-
(isFipsRegion as jest.Mock).mockReturnValue(true);
74+
vi.mocked(isFipsRegion).mockReturnValue(true);
7475
const resolvedRegionConfig = resolveRegionConfig({
7576
region: mockRegionProvider,
7677
useFipsEndpoint: mockUseFipsEndpoint,

0 commit comments

Comments
 (0)