-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Expand file tree
/
Copy pathvitest.shared.mts
More file actions
60 lines (57 loc) · 1.81 KB
/
Copy pathvitest.shared.mts
File metadata and controls
60 lines (57 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import type { ViteUserConfig } from "vitest/config";
import type { VitestEnvironment } from "vitest/node";
import { fileURLToPath } from "node:url";
import { defineConfig } from "vitest/config";
const workspaceRoot = fileURLToPath(new URL(".", import.meta.url));
const setupFile = fileURLToPath(new URL("./vitest.setup.ts", import.meta.url));
type VitestProjectOptions = {
name: string;
dirname: string;
environment?: VitestEnvironment;
plugins?: ViteUserConfig["plugins"];
};
export const createVitestProjectConfig = ({
name,
dirname,
environment = "node",
plugins = [],
}: VitestProjectOptions) =>
defineConfig({
root: dirname,
envDir: workspaceRoot,
resolve: { tsconfigPaths: true },
plugins,
test: {
name,
environment,
environmentOptions: {
happyDOM: {
settings: {
disableJavaScriptFileLoading: true,
disableCSSFileLoading: true,
navigation: {
disableMainFrameNavigation: true,
disableChildFrameNavigation: true,
disableChildPageNavigation: true,
},
},
},
},
setupFiles: [setupFile],
include: ["src/**/*.{test,spec}.?(c|m)[jt]s?(x)"],
exclude: ["node_modules", "dist", ".output", "coverage", "reports"],
pool: "threads",
// Isolation stays on: without it, test files in a worker share one module registry, so a
// `vi.mock` in one file leaks into another and whichever file imported a module first wins.
// That made every suite mocking `@reactive-resume/env/server` order-dependent and flaky.
passWithNoTests: true,
coverage: {
provider: "v8",
reportsDirectory: "coverage",
reporter: ["text", "text-summary", "json-summary", "json", "lcov", "html"],
include: ["src/**/*.{ts,tsx}"],
exclude: ["src/**/*.{test,spec}.*", "src/**/*.d.ts", "src/routeTree.gen.ts"],
reportOnFailure: true,
},
},
});