-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
79 lines (76 loc) · 3.07 KB
/
Copy pathvite.config.ts
File metadata and controls
79 lines (76 loc) · 3.07 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
70
71
72
73
74
75
76
77
78
79
import { totalmem } from "node:os";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
/// <reference types="vitest" />
import { defineConfig } from "vite";
import solid from "vite-plugin-solid";
const __dirname = dirname(fileURLToPath(import.meta.url));
// Pick a fork-pool worker cap based on host RAM.
//
// Why this exists: vitest defaults to one worker per logical CPU, and
// each worker reserves ~1 GB+ of virtual memory for V8 heap regions +
// jsdom + the Vite transform pipeline. On a memory-constrained Windows
// box (16 GB RAM + ~2.4 GB page file → ~18 GB total commit limit, of
// which baseline OS+apps already consume ~12.5 GB), 12 concurrent
// workers blow past the commit headroom and V8's Zone allocator aborts
// with "Zone Allocation failed - process out of memory" at trivial heap
// usage — sometimes single-digit MB, before any user test code runs.
//
// Scaling by total RAM means contributors on roomier boxes (32 GB, 64
// GB, CI runners) get more parallelism automatically. The
// VITEST_MAX_FORKS env var is an escape hatch if the heuristic guesses
// wrong on a given machine.
function pickMaxForks(): number | undefined {
const override = process.env.VITEST_MAX_FORKS;
if (override !== undefined && override !== "") {
const n = Number(override);
if (Number.isFinite(n) && n > 0) return n;
}
const totalGB = totalmem() / 1024 ** 3;
if (totalGB < 24) return 2; // 16 GB tier — pin to 2, OS commit is tight
if (totalGB < 48) return 4; // 32 GB tier — comfortable middle ground
return undefined; // 48 GB+ — let vitest default to one-per-CPU
}
const MAX_FORKS = pickMaxForks();
export default defineConfig({
plugins: [solid()],
resolve: {
alias: {
"@": resolve(__dirname, "src"),
},
// Resolve Solid's browser conditions so the JSX runtime uses the
// DOM-aware build during tests (and prod, which already does this).
// Without this vite-plugin-solid resolves Solid's server build in
// vitest and the first `createSignal` call throws "Client-only API
// called on the server side."
conditions: ["development", "browser"],
},
test: {
globals: true,
// Default env is node (fast, no DOM); UI component tests opt into
// jsdom per-file via a `// @vitest-environment jsdom` directive at
// the top of the file.
environment: "node",
include: ["tests/**/*.test.ts", "tests/**/*.test.tsx", "src/**/*.test.ts", "src/**/*.test.tsx"],
server: {
deps: {
// Inline solid-js so its module-resolution conditions are
// controlled by our config above, not by vitest's deps cache.
inline: [/solid-js/],
},
},
// Fork-pool concurrency cap. See pickMaxForks() above for the
// memory-pressure reasoning. When MAX_FORKS is undefined the
// poolOptions block is omitted entirely so vitest falls back to
// its default (one worker per logical CPU).
pool: "forks",
...(MAX_FORKS !== undefined && {
poolOptions: {
forks: {
maxForks: MAX_FORKS,
minForks: 1,
},
},
}),
},
});