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

test: update vitest to 2.1.8 #1496

Merged
merged 3 commits into from
Jan 8, 2025
Merged
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/angry-pugs-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
10 changes: 2 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,11 @@
"ts-jest": "29.1.2",
"turbo": "latest",
"typescript": "~5.2.2",
"vite": "4.5.5",
"vitest": "0.34.6",
"vitest": "2.1.8",
"webpack": "5.91.0",
"yarn": "1.22.22"
},
"overrides": {
"vite": "4.5.5"
},
"resolutions": {
"vite": "4.5.5"
},
"overrides": {},
"workspaces": [
"packages/*",
"smithy-typescript-ssdk-libs/*",
Expand Down
18 changes: 11 additions & 7 deletions packages/middleware-retry/src/StandardRetryStrategy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,25 +104,29 @@ describe("defaultStrategy", () => {
vi.clearAllMocks();
});

it("sets maxAttemptsProvider as class member variable", () => {
[1, 2, 3].forEach((maxAttempts) => {
const retryStrategy = new StandardRetryStrategy(() => Promise.resolve(maxAttempts));
expect(retryStrategy["maxAttemptsProvider"]()).resolves.toBe(maxAttempts);
});
it("sets maxAttemptsProvider as class member variable", async () => {
await Promise.all(
[1, 2, 3].map(async (maxAttempts) => {
const retryStrategy = new StandardRetryStrategy(() => Promise.resolve(maxAttempts));
expect(await retryStrategy["maxAttemptsProvider"]()).toBe(maxAttempts);
})
);
});

it(`sets mode=${RETRY_MODES.STANDARD}`, () => {
const retryStrategy = new StandardRetryStrategy(() => Promise.resolve(maxAttempts));
expect(retryStrategy.mode).toStrictEqual(RETRY_MODES.STANDARD);
});

it("handles non-standard errors", () => {
it("handles non-standard errors", async () => {
const nonStandardErrors = [undefined, "foo", { foo: "bar" }, 123, false, null];
const maxAttempts = 1;
const retryStrategy = new StandardRetryStrategy(() => Promise.resolve(maxAttempts));
for (const error of nonStandardErrors) {
next = vi.fn().mockRejectedValue(error);
expect(retryStrategy.retry(next, { request: { headers: {} } } as any)).rejects.toBeInstanceOf(Error);
expect(await retryStrategy.retry(next, { request: { headers: {} } } as any).catch((_) => _)).toBeInstanceOf(
Error
);
}
});

Expand Down
11 changes: 6 additions & 5 deletions packages/middleware-retry/src/configurations.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Provider } from "@smithy/types";
import { normalizeProvider } from "@smithy/util-middleware";
import { AdaptiveRetryStrategy, DEFAULT_MAX_ATTEMPTS, StandardRetryStrategy } from "@smithy/util-retry";
import { afterEach, beforeEach, describe, expect, test as it, vi } from "vitest";
Expand All @@ -17,7 +18,7 @@ describe(resolveRetryConfig.name, () => {

beforeEach(() => {
vi.mocked(normalizeProvider).mockImplementation((input) =>
typeof input === "function" ? input : () => Promise.resolve(input)
typeof input === "function" ? (input as Provider<unknown>) : () => Promise.resolve(input)
);
});

Expand All @@ -38,15 +39,15 @@ describe(resolveRetryConfig.name, () => {
});

describe("retryStrategy", () => {
it("passes retryStrategy if present", () => {
it("passes retryStrategy if present", async () => {
const mockRetryStrategy = {
retry: vi.fn(),
};
const { retryStrategy } = resolveRetryConfig({
retryMode,
retryStrategy: mockRetryStrategy,
});
expect(retryStrategy()).resolves.toEqual(mockRetryStrategy);
expect(await retryStrategy()).toEqual(mockRetryStrategy);
});

describe("creates RetryStrategy if retryStrategy not present", () => {
Expand Down Expand Up @@ -141,7 +142,7 @@ describe(resolveRetryConfig.name, () => {
it(`should throw if if value of env ${ENV_MAX_ATTEMPTS} is not a number`, () => {
const value = "not a number";
const env = { [ENV_MAX_ATTEMPTS]: value };
expect(() => NODE_MAX_ATTEMPT_CONFIG_OPTIONS.environmentVariableSelector(env)).toThrow("");
expect(() => NODE_MAX_ATTEMPT_CONFIG_OPTIONS.environmentVariableSelector(env)).toThrow();
});
});

Expand All @@ -159,7 +160,7 @@ describe(resolveRetryConfig.name, () => {
it(`should throw if shared INI files entry ${CONFIG_MAX_ATTEMPTS} is not a number`, () => {
const value = "not a number";
const profile = { [CONFIG_MAX_ATTEMPTS]: value };
expect(() => NODE_MAX_ATTEMPT_CONFIG_OPTIONS.configFileSelector(profile)).toThrow("");
expect(() => NODE_MAX_ATTEMPT_CONFIG_OPTIONS.configFileSelector(profile)).toThrow();
});
});

Expand Down
6 changes: 3 additions & 3 deletions packages/util-waiter/src/createWaiter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("createWaiter", () => {
);
vi.advanceTimersByTime(10 * 1000);
abortController.abort(); // Abort before maxWaitTime(20s);
expect(await statusPromise).toContain(abortedState);
expect(await statusPromise).toMatchObject(abortedState);
});

it("should success when acceptor checker returns seccess", async () => {
Expand All @@ -67,7 +67,7 @@ describe("createWaiter", () => {
mockAcceptorChecks
);
vi.advanceTimersByTime(minimalWaiterConfig.minDelay * 1000);
expect(await statusPromise).toContain(successState);
expect(await statusPromise).toMatchObject(successState);
});

it("should fail when acceptor checker returns failure", async () => {
Expand All @@ -81,6 +81,6 @@ describe("createWaiter", () => {
mockAcceptorChecks
);
vi.advanceTimersByTime(minimalWaiterConfig.minDelay * 1000);
expect(await statusPromise).toContain(failureState);
expect(await statusPromise).toMatchObject(failureState);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public enum TypeScriptDependency implements Dependency {
@Deprecated EXPERIMENTAL_IDENTITY_AND_AUTH("dependencies", "@smithy/experimental-identity-and-auth", false),

// Conditionally added when specs have been generated.
VITEST("devDependencies", "vitest", "^0.33.0", false),
VITEST("devDependencies", "vitest", "2.1.8", false),

// Conditionally added when `generateTypeDoc` is true.
TYPEDOC("devDependencies", "typedoc", "0.23.23", false),
Expand Down
Loading
Loading