Skip to content

Commit e09d4d9

Browse files
committed
test(*): do not manually restore mocks
This already happens via a global config now
1 parent 4dbbae4 commit e09d4d9

9 files changed

+9
-41
lines changed

test/loader/fetch-collection.e2e-spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
} from "astro/content/runtime";
55
import { randomUUID } from "crypto";
66
import {
7-
afterEach,
87
assert,
98
beforeAll,
109
beforeEach,
@@ -52,10 +51,6 @@ describe("fetchCollection", () => {
5251
superuserToken = token;
5352
});
5453

55-
afterEach(() => {
56-
vi.resetAllMocks();
57-
});
58-
5954
test("should fetch entries without errors", async () => {
6055
await fetchCollection(options, chunkLoadedMock, superuserToken, undefined);
6156

test/loader/live-collection-loader.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { LiveCollectionError } from "astro/content/runtime";
2-
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
2+
import { beforeEach, describe, expect, test, vi } from "vitest";
33
import { liveCollectionLoader } from "../../src/loader/live-collection-loader";
44
import { createLiveLoaderOptions } from "../_mocks/create-live-loader-options";
55
import { createPocketbaseEntry } from "../_mocks/create-pocketbase-entry";
@@ -16,10 +16,6 @@ describe("liveCollectionLoader", async () => {
1616
plem.parseLiveEntry = vi.fn().mockImplementation((e) => e);
1717
});
1818

19-
afterEach(() => {
20-
vi.resetAllMocks();
21-
});
22-
2319
test("should return live data collection with parsed entries", async () => {
2420
const entry = createPocketbaseEntry();
2521

test/loader/live-entry-loader.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { LiveCollectionError } from "astro/content/runtime";
2-
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
2+
import { beforeEach, describe, expect, test, vi } from "vitest";
33
import { liveEntryLoader } from "../../src/loader/live-entry-loader";
44
import { createLiveLoaderOptions } from "../_mocks/create-live-loader-options";
55
import { createPocketbaseEntry } from "../_mocks/create-pocketbase-entry";
@@ -16,10 +16,6 @@ describe("liveEntryLoader", async () => {
1616
plem.parseLiveEntry = vi.fn().mockImplementation((e) => e);
1717
});
1818

19-
afterEach(() => {
20-
vi.resetAllMocks();
21-
});
22-
2319
test("should return parsed entry", async () => {
2420
const entry = createPocketbaseEntry();
2521
fem.fetchEntry = vi.fn().mockResolvedValue(entry);

test/loader/load-entries.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { LoaderContext } from "astro/loaders";
2-
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
2+
import { beforeEach, describe, expect, test, vi } from "vitest";
33
import { loadEntries } from "../../src/loader/load-entries";
44
import { createLoaderContext } from "../_mocks/create-loader-context";
55
import { createLoaderOptions } from "../_mocks/create-loader-options";
@@ -18,10 +18,6 @@ describe("loadEntries", async () => {
1818
context = createLoaderContext();
1919
});
2020

21-
afterEach(() => {
22-
vi.resetAllMocks();
23-
});
24-
2521
test("should call fetchCollection and parseEntry for each entry", async () => {
2622
const entry = createPocketbaseEntry();
2723

test/loader/loader.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { LoaderContext } from "astro/loaders";
2-
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
2+
import { beforeEach, describe, expect, test, vi } from "vitest";
33
import packageJson from "../../package.json";
44
import { cleanupEntries } from "../../src/loader/cleanup-entries";
55
import { handleRealtimeUpdates } from "../../src/loader/handle-realtime-updates";
@@ -29,10 +29,6 @@ describe("loader", async () => {
2929
);
3030
});
3131

32-
afterEach(() => {
33-
vi.resetAllMocks();
34-
});
35-
3632
test('should not refresh if shouldRefresh returns "skip"', async () => {
3733
srm.shouldRefresh = vi.fn().mockReturnValue("skip");
3834

test/loader/parse-entry.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { LoaderContext } from "astro/loaders";
2-
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
2+
import { beforeEach, describe, expect, test, vi } from "vitest";
33
import { parseEntry } from "../../src/loader/parse-entry";
44
import type { PocketBaseEntry } from "../../src/types/pocketbase-entry.type";
55
import { createLoaderContext } from "../_mocks/create-loader-context";
@@ -15,10 +15,6 @@ describe("parseEntry", () => {
1515
entry = createPocketbaseEntry();
1616
});
1717

18-
afterEach(() => {
19-
vi.resetAllMocks();
20-
});
21-
2218
test("should use default ID if no custom ID field is provided", async () => {
2319
const options = createLoaderOptions();
2420

test/schema/generate-schema.e2e-spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ZodObject, ZodSchema } from "astro/zod";
2-
import { afterEach, assert, beforeAll, describe, expect, it, vi } from "vitest";
2+
import { assert, beforeAll, describe, expect, it, vi } from "vitest";
33
import type { PocketBaseLoaderOptions } from "../../src";
44
import { generateSchema } from "../../src/schema/generate-schema";
55
import { transformFileUrl } from "../../src/schema/transform-files";
@@ -29,10 +29,6 @@ describe("generateSchema", () => {
2929
token = superuserToken;
3030
});
3131

32-
afterEach(() => {
33-
vi.resetAllMocks();
34-
});
35-
3632
describe("load and parse schema", () => {
3733
it("should return basic schema if no schema is available", async () => {
3834
const result = (await generateSchema(

test/schema/read-local-schema.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from "fs/promises";
22
import path from "path";
3-
import { beforeEach, describe, expect, test, vi } from "vitest";
3+
import { describe, expect, test, vi } from "vitest";
44
import { readLocalSchema } from "../../src/schema/read-local-schema";
55

66
vi.mock("fs/promises");
@@ -21,10 +21,6 @@ describe("readLocalSchema", () => {
2121
}
2222
];
2323

24-
beforeEach(() => {
25-
vi.clearAllMocks();
26-
});
27-
2824
test("should return the schema for the specified collection", async () => {
2925
vi.spyOn(path, "join").mockReturnValue(localSchemaPath);
3026
vi.spyOn(fs, "readFile").mockResolvedValue(JSON.stringify(mockSchema));

vitest.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default defineConfig({
77
coverage: {
88
include: ["src/**/*.ts"],
99
exclude: ["src/types/**/*.ts", "src/index.ts", "src/pocketbase-loader.ts"]
10-
}
10+
},
11+
restoreMocks: true
1112
}
1213
});

0 commit comments

Comments
 (0)