Skip to content

Commit 696f1c8

Browse files
chore: Upgrade vitest from v2 to v4 (#1192)
* chore: upgrade vitest to v4 * docs: fix changeset description for vitest v4 upgrade * test: configure global mock cleanup in vitest and fix spy isolation * test: replace deprecated Vitest call matchers * test: limit vitest discovery to src directory * remove changeset --------- Co-authored-by: James <james@eli.cx>
1 parent 87b40d1 commit 696f1c8

15 files changed

Lines changed: 688 additions & 537 deletions

packages/cloudflare/src/api/overrides/queue/memory-queue.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ describe("MemoryQueue", () => {
2828
return () => {
2929
vi.useRealTimers();
3030
vi.unstubAllEnvs();
31-
vi.clearAllMocks();
3231
};
3332
});
3433

packages/cloudflare/src/api/overrides/tag-cache/d1-next-tag-cache.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ describe("D1NextModeTagCache", () => {
3333
let mockBatch: ReturnType<typeof vi.fn>;
3434

3535
beforeEach(() => {
36-
vi.clearAllMocks();
37-
3836
// Setup mock database.
3937
// All read methods now use .raw() (via #resolveTagValues) to fetch full rows.
4038
mockRaw = vi.fn().mockResolvedValue([]);

packages/cloudflare/src/api/overrides/tag-cache/do-sharded-tag-cache.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ vi.mock("../../cloudflare-context", () => ({
3030
}));
3131

3232
describe("DOShardedTagCache", () => {
33-
afterEach(() => vi.clearAllMocks());
34-
3533
describe("generateShardId", () => {
3634
it("should generate a shardId", () => {
3735
const cache = shardedDOTagCache();

packages/cloudflare/src/api/overrides/tag-cache/kv-next-tag-cache.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ describe("KVNextModeTagCache", () => {
3131
let mockPut: ReturnType<typeof vi.fn>;
3232

3333
beforeEach(() => {
34-
vi.clearAllMocks();
35-
3634
// Setup mock database
3735
mockGet = vi.fn();
3836
mockPut = vi.fn();

packages/cloudflare/src/api/overrides/tag-cache/tag-cache-filter.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NextModeTagCache } from "@opennextjs/aws/types/overrides.js";
2-
import { beforeEach, describe, expect, it, vi } from "vitest";
2+
import { describe, expect, it, vi } from "vitest";
33

44
import { softTagFilter, withFilter } from "./tag-cache-filter.js";
55

@@ -16,10 +16,6 @@ const mockedTagCache = {
1616
const filterFn = (tag: string) => tag.startsWith("valid_");
1717

1818
describe("withFilter", () => {
19-
beforeEach(() => {
20-
vi.clearAllMocks();
21-
});
22-
2319
it("should filter out tags based on writeTags", async () => {
2420
const tagCache = withFilter({
2521
tagCache: mockedTagCache,

packages/cloudflare/src/cli/build/patches/plugins/use-cache.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ function createSnapshot() {
7676
return fn(...args);
7777
};
7878
}
79-
80-
//# sourceMappingURL=async-local-storage.js.map
8179
`;
8280

8381
test("patch the createSnapshot function", () => {

packages/cloudflare/src/cli/commands/build.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logger from "@opennextjs/aws/logger.js";
2-
import { afterEach, describe, expect, it, vi } from "vitest";
2+
import { describe, expect, it, vi } from "vitest";
33

44
import { askConfirmation } from "../utils/ask-confirmation.js";
55
import { createWranglerConfigFile } from "../utils/create-wrangler-config.js";
@@ -55,10 +55,6 @@ const defaultArgs = {
5555
};
5656

5757
describe("buildCommand", () => {
58-
afterEach(() => {
59-
vi.restoreAllMocks();
60-
});
61-
6258
it("should create wrangler config when user confirms", async () => {
6359
vi.mocked(askConfirmation).mockResolvedValue(true);
6460

packages/cloudflare/src/cli/commands/populate-cache.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ describe("populateCache", () => {
188188
expect(ensureR2Bucket).not.toHaveBeenCalled();
189189
}
190190

191-
expect(fetchMock).toBeCalled();
191+
expect(fetchMock).toHaveBeenCalled();
192192

193193
for (const [input, init] of fetchMock.mock.calls) {
194194
expect(input).toBe("http://localhost:12345/populate");
@@ -285,6 +285,7 @@ describe("populateCache", () => {
285285
test("retries 5xx responses from the R2 worker", async () => {
286286
setupMockFileSystem();
287287
vi.useFakeTimers();
288+
vi.spyOn(AbortSignal, "timeout");
288289

289290
const mockWorkerDispose = vi.fn();
290291
// @ts-expect-error - Mock unstable_startWorker to return a mock worker instance

packages/cloudflare/src/cli/commands/populate-cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ async function sendEntryToR2Worker(options: {
412412
"x-opennext-cache-key": key,
413413
"content-length": fs.statSync(filename).size.toString(),
414414
},
415-
body: Readable.toWeb(fs.createReadStream(filename)) as ReadableStream,
415+
body: Readable.toWeb(fs.createReadStream(filename)) as unknown as ReadableStream,
416416
signal: AbortSignal.timeout(60_000),
417417
// @ts-expect-error - `duplex` is required for streaming request bodies in Node.js
418418
duplex: "half",

packages/cloudflare/src/cli/commands/utils/utils.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterEach, describe, expect, it, vi } from "vitest";
1+
import { describe, expect, it, vi } from "vitest";
22

33
import { askConfirmation } from "../../utils/ask-confirmation.js";
44
import { createOpenNextConfigFile, findOpenNextConfig } from "../../utils/create-open-next-config.js";
@@ -66,10 +66,6 @@ vi.mock("@opennextjs/aws/build/helper.js", () => ({
6666
}));
6767

6868
describe("compileConfig", () => {
69-
afterEach(() => {
70-
vi.restoreAllMocks();
71-
});
72-
7369
it("should compile config when configPath is provided and file exists", async () => {
7470
mockExistsSync.mockReturnValue(true);
7571

0 commit comments

Comments
 (0)