Skip to content

Commit d7bf51a

Browse files
committed
chore: install vitest
1 parent 053a868 commit d7bf51a

21 files changed

+489
-26
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
"turbo": "2.1.2",
122122
"typescript": "~4.9.5",
123123
"verdaccio": "5.25.0",
124+
"vitest": "0.34.6",
124125
"webpack": "5.76.0",
125126
"webpack-cli": "4.10.0",
126127
"yargs": "17.5.1",

packages/core/integ/request-handlers/request-handlers.integ.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { XhrHttpHandler } from "@aws-sdk/xhr-http-handler";
66
import { FetchHttpHandler } from "@smithy/fetch-http-handler";
77
import { NodeHttp2Handler, NodeHttpHandler } from "@smithy/node-http-handler";
88
import { Agent } from "https";
9+
import { describe, expect, test as it } from "vitest";
910

1011
describe("request handler initialization", () => {
1112
describe("http", () => {

packages/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"lint": "node ./scripts/lint.js",
1313
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
1414
"extract:docs": "api-extractor run --local",
15-
"test": "jest",
16-
"test:integration": "jest -c jest.config.integ.js"
15+
"test": "vitest run",
16+
"test:integration": "vitest run -c vitest.config.integ.ts"
1717
},
1818
"main": "./dist-cjs/index.js",
1919
"module": "./dist-es/index.js",

packages/core/src/submodules/account-id-endpoint/AccountIdEndpointModeConstants.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, test as it } from "vitest";
2+
13
import { validateAccountIdEndpointMode } from "./AccountIdEndpointModeConstants";
24

35
describe("validateAccountIdEndpointMode", () => {

packages/core/src/submodules/account-id-endpoint/NodeAccountIdEndpointModeConfigOptions.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { afterEach, beforeEach, describe, expect, test as it, vi } from "vitest";
2+
13
import { DEFAULT_ACCOUNT_ID_ENDPOINT_MODE } from "./AccountIdEndpointModeConstants";
24
import {
35
CONFIG_ACCOUNT_ID_ENDPOINT_MODE,
@@ -9,7 +11,7 @@ describe("NODE_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_OPTIONS", () => {
911
const originalEnv = process.env;
1012

1113
beforeEach(() => {
12-
jest.resetModules();
14+
vi.resetModules();
1315
process.env = { ...originalEnv };
1416
});
1517

packages/core/src/submodules/client/emitWarningIfUnsupportedVersion.spec.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
import { afterEach, describe, expect, test as it, vi } from "vitest";
2+
3+
import { emitWarningIfUnsupportedVersion, state } from "./emitWarningIfUnsupportedVersion";
4+
15
describe("emitWarningIfUnsupportedVersion", () => {
2-
let emitWarningIfUnsupportedVersion: any;
36
const emitWarning = process.emitWarning;
47
const supportedVersion = "18.0.0";
58

6-
beforeEach(() => {
7-
const module = require("./emitWarningIfUnsupportedVersion");
8-
emitWarningIfUnsupportedVersion = module.emitWarningIfUnsupportedVersion;
9-
});
9+
vi.spyOn(process, "emitWarning");
1010

1111
afterEach(() => {
12-
jest.clearAllMocks();
13-
jest.resetModules();
12+
state.warningEmitted = false;
13+
vi.clearAllMocks();
14+
vi.resetModules();
1415
process.emitWarning = emitWarning;
1516
});
1617

@@ -31,7 +32,7 @@ describe("emitWarningIfUnsupportedVersion", () => {
3132
[getPreviousMajorVersion(major), 0, 0],
3233
].map((arr) => `v${arr.join(".")}`)
3334
)(`%s`, async (unsupportedVersion) => {
34-
process.emitWarning = jest.fn();
35+
process.emitWarning = vi.fn() as any;
3536
emitWarningIfUnsupportedVersion(unsupportedVersion);
3637

3738
// Verify that the warning was emitted.
@@ -62,7 +63,7 @@ More information can be found at: https://a.co/74kJMmI`
6263
[major + 1, 0, 0],
6364
].map((arr) => `v${arr.join(".")}`)
6465
)(`%s`, async (unsupportedVersion) => {
65-
process.emitWarning = jest.fn();
66+
process.emitWarning = vi.fn() as any;
6667
emitWarningIfUnsupportedVersion(unsupportedVersion);
6768
expect(process.emitWarning).not.toHaveBeenCalled();
6869
});

packages/core/src/submodules/client/emitWarningIfUnsupportedVersion.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
// Stores whether the warning was already emitted.
2-
let warningEmitted = false;
1+
/**
2+
* @internal
3+
* Stores whether the warning was already emitted.
4+
*/
5+
export const state = {
6+
warningEmitted: false,
7+
};
38

49
/**
510
* @internal
@@ -10,8 +15,8 @@ let warningEmitted = false;
1015
* @param version - The Node.js version string.
1116
*/
1217
export const emitWarningIfUnsupportedVersion = (version: string) => {
13-
if (version && !warningEmitted && parseInt(version.substring(1, version.indexOf("."))) < 18) {
14-
warningEmitted = true;
18+
if (version && !state.warningEmitted && parseInt(version.substring(1, version.indexOf("."))) < 18) {
19+
state.warningEmitted = true;
1520
process.emitWarning(
1621
`NodeDeprecationWarning: The AWS SDK for JavaScript (v3) will
1722
no longer support Node.js 16.x on January 6, 2025.

packages/core/src/submodules/client/setCredentialFeature.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { AttributedAwsCredentialIdentity } from "@aws-sdk/types";
2+
import { describe, expect, test as it } from "vitest";
23

34
import { setCredentialFeature } from "./setCredentialFeature";
45

packages/core/src/submodules/client/setFeature.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { AwsHandlerExecutionContext } from "@aws-sdk/types";
2+
import { describe, expect, test as it } from "vitest";
23

34
import { setFeature } from "./setFeature";
45

packages/core/src/submodules/httpAuthSchemes/aws_sdk/AwsSdkSigV4Signer.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, test as it } from "vitest";
2+
13
import { AwsSdkSigV4Signer } from "./AwsSdkSigV4Signer";
24

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

packages/core/src/submodules/httpAuthSchemes/aws_sdk/resolveAwsSdkSigV4AConfig.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, test as it } from "vitest";
2+
13
import { resolveAwsSdkSigV4AConfig } from "./resolveAwsSdkSigV4AConfig";
24

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

packages/core/src/submodules/httpAuthSchemes/utils/getSkewCorrectedDate.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
import { afterEach, beforeEach, describe, expect, test as it, vi } from "vitest";
2+
13
import { getSkewCorrectedDate } from "./getSkewCorrectedDate";
24

35
describe(getSkewCorrectedDate.name, () => {
46
const mockDateNow = Date.now();
57

68
beforeEach(() => {
7-
jest.spyOn(Date, "now").mockReturnValue(mockDateNow);
9+
vi.spyOn(Date, "now").mockReturnValue(mockDateNow);
810
});
911

1012
afterEach(() => {
11-
jest.clearAllMocks();
13+
vi.clearAllMocks();
1214
});
1315

1416
it.each([-100000, -100, 0, 100, 100000])("systemClockOffset: %d", (systemClockOffset) => {

packages/core/src/submodules/httpAuthSchemes/utils/getUpdatedSystemClockOffset.spec.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
1+
import { afterEach, beforeEach, describe, expect, test as it, vi } from "vitest";
2+
13
import { getUpdatedSystemClockOffset } from "./getUpdatedSystemClockOffset";
24
import { isClockSkewed } from "./isClockSkewed";
35

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

68
describe(getUpdatedSystemClockOffset.name, () => {
79
// Mock ServerTime is accurate to last second, to remove milliseconds information.
810
const mockClockTime = new Date(Math.floor(Date.now() / 1000) * 1000);
911
const mockSystemClockOffset = 100;
1012

1113
afterEach(() => {
12-
jest.clearAllMocks();
14+
vi.clearAllMocks();
1315
});
1416

1517
it("returns passed systemClockOffset when clock is not skewed", () => {
16-
(isClockSkewed as jest.Mock).mockReturnValue(false);
18+
vi.mocked(isClockSkewed).mockReturnValue(false);
1719
expect(getUpdatedSystemClockOffset(mockClockTime.toString(), mockSystemClockOffset)).toEqual(mockSystemClockOffset);
1820
});
1921

2022
describe("returns difference between serverTime and current time when clock is skewed", () => {
2123
const dateDotNowFn = Date.now;
2224

2325
beforeEach(() => {
24-
(isClockSkewed as jest.Mock).mockReturnValue(true);
25-
jest.spyOn(Date, "now").mockReturnValueOnce(mockClockTime.getTime());
26+
vi.mocked(isClockSkewed).mockReturnValue(true);
27+
vi.spyOn(Date, "now").mockReturnValueOnce(mockClockTime.getTime());
2628
});
2729

2830
afterEach(() => {

packages/core/src/submodules/httpAuthSchemes/utils/isClockSkewed.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { afterEach, beforeEach, describe, expect, test as it, vi } from "vitest";
2+
13
import { getSkewCorrectedDate } from "./getSkewCorrectedDate";
24
import { isClockSkewed } from "./isClockSkewed";
35

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

68
describe(isClockSkewed.name, () => {
79
const mockSystemClockOffset = 100;
@@ -13,7 +15,7 @@ describe(isClockSkewed.name, () => {
1315

1416
afterEach(() => {
1517
expect(getSkewCorrectedDate).toHaveBeenCalledWith(mockSystemClockOffset);
16-
jest.clearAllMocks();
18+
vi.clearAllMocks();
1719
});
1820

1921
describe("returns true for time difference >=300000", () => {

packages/core/src/submodules/protocols/coercing-serializers.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { afterAll, beforeAll, describe, expect, test as it } from "vitest";
2+
13
import { _toBool, _toNum, _toStr } from "./coercing-serializers";
24

35
const consoleWarn = console.warn;

packages/core/src/submodules/protocols/json/awsExpectUnion.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, test as it } from "vitest";
2+
13
import { awsExpectUnion } from "./awsExpectUnion";
24

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

packages/core/src/submodules/protocols/xml/parseXmlBody.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { SerdeContext } from "@smithy/types";
22
import { toUtf8 } from "@smithy/util-utf8";
3+
import { describe, expect, test as it } from "vitest";
34

45
import { parseXmlBody } from "./parseXmlBody";
56

packages/core/vitest.config.integ.ts

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

packages/core/vitest.config.ts

Lines changed: 9 additions & 0 deletions
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,js}"],
6+
include: ["**/*.spec.{ts,js}"],
7+
environment: "node",
8+
},
9+
});

vite.workspace.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default ["{packages,clients,lib,private}/*/vitest.config.{e2e,integ,browser}.ts"];

0 commit comments

Comments
 (0)