-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvitest.config.ts
More file actions
57 lines (49 loc) · 1.8 KB
/
Copy pathvitest.config.ts
File metadata and controls
57 lines (49 loc) · 1.8 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
/**
* Vitest configuration for frontend tests. Dedicated config file to help VS
* Code testing extension recognize frontend tests. Settings match the test
* configuration from vite.config.ts.
*/
import {
defineConfig,
mergeConfig,
type ViteUserConfig,
type ViteUserConfigFnObject,
} from "vitest/config";
import viteConfig from "./vite.config";
export default defineConfig((configEnv) => {
const resolvedViteConfig = (() => {
const configOrPromise =
typeof viteConfig === "function"
? viteConfig(configEnv)
: viteConfig;
if (configOrPromise instanceof Promise) {
throw new TypeError(
"Async Vite config exports are not supported in vitest.config.ts."
);
}
return configOrPromise;
})();
const mergedConfig = mergeConfig(
resolvedViteConfig,
defineConfig({
cacheDir: "./.cache/vitest/", // Separate cache to avoid conflicts
test: {
environment: "jsdom",
name: {
color: "cyan",
label: "Frontend",
}, // Custom project name and color for Vitest
restoreMocks: true,
slowTestThreshold: 300,
},
})
) as ViteUserConfig;
// Frontend runs should execute only the frontend test project.
// The base Vite config defines a multi-project workspace for broader
// validation tasks, but inheriting it here causes `test:frontend` to pull
// in additional projects and can leave background handles alive.
if (mergedConfig.test && "projects" in mergedConfig.test) {
delete mergedConfig.test.projects;
}
return mergedConfig;
}) satisfies ViteUserConfigFnObject as ViteUserConfigFnObject;