Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from jest/karma to vitest #1276

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/small-dolphins-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"extract:docs": "mkdir -p api-extractor-packages && turbo run extract:docs",
"release": "yarn changeset publish",
"build-test-packages": "./gradlew clean build && node ./scripts/build-generated-test-packages",
"g:jest": "cd $INIT_CWD && jest",
"g:vitest": "cd $INIT_CWD && vitest",
"g:karma": "cd $INIT_CWD && karma",
"g:tsc": "cd $INIT_CWD && tsc"
},
Expand All @@ -37,16 +37,13 @@
"devDependencies": {
"@microsoft/api-extractor": "7.34.4",
"@tsconfig/recommended": "1.0.2",
"@types/jest": "28.1.3",
"@typescript-eslint/eslint-plugin": "7.8.0",
"@typescript-eslint/parser": "7.8.0",
"esbuild": "0.19.11",
"eslint": "8.57.0",
"eslint-plugin-simple-import-sort": "7.0.0",
"eslint-plugin-tsdoc": "0.2.17",
"husky": "^4.2.3",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"karma": "6.4.3",
"karma-chrome-launcher": "3.2.0",
"karma-firefox-launcher": "2.1.3",
Expand All @@ -55,9 +52,9 @@
"karma-webpack": "5.0.1",
"prettier": "3.2.5",
"puppeteer": "^19.2.0",
"ts-jest": "29.1.2",
"turbo": "latest",
"typescript": "~4.9.5",
"vitest": "^1.6.0",
"webpack": "5.91.0",
"yarn": "1.22.22"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/abort-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
"format": "prettier --config ../../prettier.config.js --ignore-path ../.prettierignore --write \"**/*.{ts,md,json}\"",
"extract:docs": "api-extractor run --local",
"test": "yarn g:jest"
"test": "yarn g:vitest"
},
"author": {
"name": "AWS SDK for JavaScript Team",
Expand Down
4 changes: 2 additions & 2 deletions packages/abort-controller/src/AbortSignal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("AbortSignal", () => {
it("should invoke the onabort handler when the signal is aborted", () => {
const controller = new AbortController();
const { signal } = controller;
const abortHandler = jest.fn();
const abortHandler = vi.fn();
signal.onabort = abortHandler;
expect(abortHandler.mock.calls.length).toBe(0);
controller.abort();
Expand All @@ -23,7 +23,7 @@ describe("AbortSignal", () => {
it("should not invoke the onabort handler multiple time", () => {
const controller = new AbortController();
const { signal } = controller;
const abortHandler = jest.fn();
const abortHandler = vi.fn();
signal.onabort = abortHandler;
expect(abortHandler.mock.calls.length).toBe(0);
controller.abort();
Expand Down
2 changes: 1 addition & 1 deletion packages/chunked-blob-reader-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo || exit 0",
"lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
"format": "prettier --config ../../prettier.config.js --ignore-path ../.prettierignore --write \"**/*.{ts,md,json}\"",
"test": "yarn g:jest"
"test": "yarn g:vitest"
},
"main": "./dist-cjs/index.js",
"module": "./dist-es/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/chunked-blob-reader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo || exit 0",
"lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
"format": "prettier --config ../../prettier.config.js --ignore-path ../.prettierignore --write \"**/*.{ts,md,json}\"",
"test": "yarn g:jest"
"test": "yarn g:vitest"
},
"main": "./dist-cjs/index.js",
"module": "./dist-es/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/config-resolver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo || exit 0",
"lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
"format": "prettier --config ../../prettier.config.js --ignore-path ../.prettierignore --write \"**/*.{ts,md,json}\"",
"test": "yarn g:jest",
"test": "yarn g:vitest",
"extract:docs": "api-extractor run --local"
},
"main": "./dist-cjs/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe(resolveCustomEndpointsConfig.name, () => {

const mockInput = {
endpoint: mockEndpoint,
urlParser: jest.fn(() => mockEndpoint),
urlParser: vi.fn(() => mockEndpoint),
useDualstackEndpoint: () => Promise.resolve(false),
} as any;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe(resolveEndpointsConfig.name, () => {

const mockInput = {
endpoint: mockEndpoint,
urlParser: jest.fn(() => mockEndpoint),
urlParser: vi.fn(() => mockEndpoint),
useDualstackEndpoint: () => Promise.resolve(false),
useFipsEndpoint: () => Promise.resolve(false),
} as any;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getEndpointFromRegion } from "./getEndpointFromRegion";

describe(getEndpointFromRegion.name, () => {
const mockRegion = jest.fn();
const mockUrlParser = jest.fn();
const mockRegionInfoProvider = jest.fn();
const mockUseFipsEndpoint = jest.fn();
const mockUseDualstackEndpoint = jest.fn();
const mockRegion = vi.fn();
const mockUrlParser = vi.fn();
const mockRegionInfoProvider = vi.fn();
const mockUseFipsEndpoint = vi.fn();
const mockUseDualstackEndpoint = vi.fn();

const mockInput = {
region: mockRegion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ describe("RegionConfig", () => {
let mockUseFipsEndpoint;

beforeEach(() => {
mockRegionProvider = jest.fn().mockResolvedValueOnce(Promise.resolve(mockRegion));
mockUseFipsEndpoint = jest.fn().mockResolvedValueOnce(Promise.resolve(false));
mockRegionProvider = vi.fn().mockResolvedValueOnce(Promise.resolve(mockRegion));
mockUseFipsEndpoint = vi.fn().mockResolvedValueOnce(Promise.resolve(false));
});

afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo || exit 0",
"lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
"format": "prettier --config ../../prettier.config.js --ignore-path ../.prettierignore --write \"**/*.{ts,md,json}\"",
"test": "yarn g:jest"
"test": "yarn g:vitest"
},
"main": "./dist-cjs/index.js",
"module": "./dist-es/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/credential-provider-imds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo || exit 0",
"lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
"format": "prettier --config ../../prettier.config.js --ignore-path ../.prettierignore --write \"**/*.{ts,md,json}\"",
"test": "yarn g:jest"
"test": "yarn g:vitest"
},
"keywords": [
"aws",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe("retry", () => {
const successMsg = "Success";
const errorMsg = "Expected failure";
const retries = 10;
const retryable = jest.fn().mockRejectedValue(errorMsg);
const retryable = vi.fn().mockRejectedValue(errorMsg);

afterEach(() => {
jest.clearAllMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("getExtendedInstanceMetadataCredentials()", () => {
secretAccessKey: "secret",
};
const logger: Logger = {
warn: jest.fn(),
warn: vi.fn(),
} as any;

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("staticStabilityProvider", () => {
});

it("should refresh credentials if provider is functional", async () => {
const provider = jest.fn();
const provider = vi.fn();
const stableProvider = staticStabilityProvider(provider);
const repeat = 3;
for (let i = 0; i < repeat; i++) {
Expand All @@ -46,7 +46,7 @@ describe("staticStabilityProvider", () => {
});

it("should throw if cannot load credentials at 1st load", async () => {
const provider = jest.fn().mockRejectedValue("Error");
const provider = vi.fn().mockRejectedValue("Error");
try {
await staticStabilityProvider(provider)();
fail("This provider should throw");
Expand All @@ -58,7 +58,7 @@ describe("staticStabilityProvider", () => {
});

it("should extend expired credentials if refresh fails", async () => {
const provider = jest.fn().mockResolvedValueOnce(mockCreds).mockRejectedValue("Error");
const provider = vi.fn().mockResolvedValueOnce(mockCreds).mockRejectedValue("Error");
const stableProvider = staticStabilityProvider(provider);
expect(await stableProvider()).toEqual(mockCreds);
const repeat = 3;
Expand All @@ -76,7 +76,7 @@ describe("staticStabilityProvider", () => {

it("should extend expired credentials if loaded expired credentials", async () => {
const ONE_HOUR_AGO = new Date(Date.now() - 60 * 60 * 1000);
const provider = jest.fn().mockResolvedValue({ ...mockCreds, expiration: ONE_HOUR_AGO });
const provider = vi.fn().mockResolvedValue({ ...mockCreds, expiration: ONE_HOUR_AGO });
const stableProvider = staticStabilityProvider(provider);
const repeat = 3;
for (let i = 0; i < repeat; i++) {
Expand All @@ -88,8 +88,8 @@ describe("staticStabilityProvider", () => {
});

it("should allow custom logger to print warning messages", async () => {
const provider = jest.fn().mockResolvedValueOnce(mockCreds).mockRejectedValue("Error");
const logger = { warn: jest.fn() } as unknown as Logger;
const provider = vi.fn().mockResolvedValueOnce(mockCreds).mockRejectedValue("Error");
const logger = { warn: vi.fn() } as unknown as Logger;
const stableProvider = staticStabilityProvider(provider, { logger });
expect(await stableProvider()).toEqual(mockCreds); // load initial creds
await stableProvider();
Expand Down
2 changes: 1 addition & 1 deletion packages/eventstream-codec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo || exit 0",
"lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
"format": "prettier --config ../../prettier.config.js --ignore-path ../.prettierignore --write \"**/*.{ts,md,json}\"",
"test": "yarn g:jest --coverage"
"test": "yarn g:vitest"
},
"main": "./dist-cjs/index.js",
"module": "./dist-es/index.js",
Expand Down
10 changes: 5 additions & 5 deletions packages/eventstream-codec/src/MessageDecoderStream.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ describe("MessageDecoderStream", () => {
};

const messageDecoderMock = {
decode: jest.fn().mockReturnValueOnce(message1).mockReturnValueOnce(message2),
feed: jest.fn(),
endOfStream: jest.fn(),
getMessage: jest.fn(),
getAvailableMessages: jest.fn(),
decode: vi.fn().mockReturnValueOnce(message1).mockReturnValueOnce(message2),
feed: vi.fn(),
endOfStream: vi.fn(),
getMessage: vi.fn(),
getAvailableMessages: vi.fn(),
};

const inputStream = async function* () {
Expand Down
4 changes: 2 additions & 2 deletions packages/eventstream-codec/src/MessageEncoderStream.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("MessageEncoderStream", () => {
};

const messageEncoderMock = {
encode: jest.fn().mockReturnValueOnce(new Uint8Array(1)).mockReturnValueOnce(new Uint8Array(2)),
encode: vi.fn().mockReturnValueOnce(new Uint8Array(1)).mockReturnValueOnce(new Uint8Array(2)),
};

const inputStream = async function* () {
Expand Down Expand Up @@ -49,7 +49,7 @@ describe("MessageEncoderStream", () => {
};

const messageEncoderMock = {
encode: jest.fn().mockReturnValueOnce(new Uint8Array(1)).mockReturnValueOnce(new Uint8Array(2)),
encode: vi.fn().mockReturnValueOnce(new Uint8Array(1)).mockReturnValueOnce(new Uint8Array(2)),
};

const inputStream = async function* () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe("SmithyMessageEncoderStream", () => {
body: new Uint8Array(2),
};

const serializer = jest.fn().mockReturnValueOnce(message1).mockReturnValueOnce(message2);
const serializer = vi.fn().mockReturnValueOnce(message1).mockReturnValueOnce(message2);

const inputStream = async function* () {
yield "first";
Expand Down
2 changes: 1 addition & 1 deletion packages/eventstream-serde-config-resolver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo || exit 0",
"lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
"format": "prettier --config ../../prettier.config.js --ignore-path ../.prettierignore --write \"**/*.{ts,md,json}\"",
"test": "yarn g:jest",
"test": "yarn g:vitest",
"extract:docs": "api-extractor run --local"
},
"main": "./dist-cjs/index.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { resolveEventStreamSerdeConfig } from "./EventStreamSerdeConfig";

describe("resolveEventStreamSerdeConfig", () => {
const eventStreamSerdeProvider = jest.fn();
const eventStreamSerdeProvider = vi.fn();

afterEach(() => {
jest.clearAllMocks();
Expand Down
2 changes: 1 addition & 1 deletion packages/eventstream-serde-universal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo || exit 0",
"lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
"format": "prettier --config ../../prettier.config.js --ignore-path ../.prettierignore --write \"**/*.{ts,md,json}\"",
"test": "yarn g:jest"
"test": "yarn g:vitest"
},
"main": "./dist-cjs/index.js",
"module": "./dist-es/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/experimental-identity-and-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo || exit 0",
"lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
"format": "prettier --config ../../prettier.config.js --ignore-path ../.prettierignore --write \"**/*.{ts,md,json}\"",
"test": "yarn g:jest --passWithNoTests",
"test:integration": "yarn g:jest --config jest.config.integ.js --passWithNoTests"
"test": "yarn g:vitest --passWithNoTests",
"test:integration": "yarn g:vitest --config jest.config.integ.js --passWithNoTests"
},
"main": "./dist-cjs/index.js",
"module": "./dist-es/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/fetch-http-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
"format": "prettier --config ../../prettier.config.js --ignore-path ../.prettierignore --write \"**/*.{ts,md,json}\"",
"extract:docs": "api-extractor run --local",
"test": "yarn g:jest --coverage --forceExit && yarn g:karma start karma.conf.js"
"test": "yarn g:vitest && yarn g:karma start karma.conf.js"
},
"author": {
"name": "AWS SDK for JavaScript Team",
Expand Down
Loading
Loading