Repository navigation
Expand file tree
/
Copy pathvitest.config.ts
More file actions
69 lines (59 loc) · 2.06 KB
/
Copy pathvitest.config.ts
File metadata and controls
69 lines (59 loc) · 2.06 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
61
62
63
64
65
66
67
68
69
import { globSync, readFileSync } from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { paraglideVitePlugin } from "@inlang/paraglide-js";
import react from "@vitejs/plugin-react";
import svgr from "vite-plugin-svgr";
import { configDefaults, defineConfig } from "vitest/config";
import { releaseNotes } from "./scripts/vite-release-notes";
import { phosphorIconImports } from "./scripts/vitest-phosphor-imports";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const TEST_FILES = "src/**/*.test.{ts,tsx}";
/** Matches a test file that mocks, spies, fakes timers, stubs globals, reads `@/test/mocks` or needs a DOM. */
const NEEDS_ISOLATION =
/vi\.(mock|doMock|hoisted|spyOn|useFakeTimers|stubGlobal|stubEnv)\b|@vitest-environment|@\/test\/mocks/;
/** Test files that can share one module registry per worker, which skips a re-import per file. */
const sharedFiles = globSync(TEST_FILES, { cwd: __dirname })
.map((file) => file.replaceAll("\\", "/"))
.filter((file) => !NEEDS_ISOLATION.test(readFileSync(path.join(__dirname, file), "utf8")));
export default defineConfig({
plugins: [
paraglideVitePlugin({ project: "./project.inlang" }),
react({ compiler: true }),
svgr(),
releaseNotes(__dirname),
phosphorIconImports(__dirname),
],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
test: {
globals: true,
setupFiles: ["./src/test/setup.ts"],
coverage: {
provider: "v8",
exclude: [
"src/routeTree.gen.ts",
"src/lib/bindings.ts",
"src/lib/ipc/**",
"src/test/**",
"**/*.config.*",
],
},
environment: "node",
projects: [
{ extends: true, test: { name: "shared", include: sharedFiles, isolate: false } },
{
extends: true,
test: {
name: "isolated",
include: [TEST_FILES, "scripts/**/*.test.mjs"],
exclude: [...configDefaults.exclude, ...sharedFiles],
},
},
],
experimental: { fsModuleCache: !process.env.CI },
},
});