Repository navigation
Expand file tree
/
Copy pathvitest.config.ts
More file actions
116 lines (110 loc) · 3.58 KB
/
Copy pathvitest.config.ts
File metadata and controls
116 lines (110 loc) · 3.58 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vitest/config';
const include = ['tests/**/*.test.ts'];
/** The bindings' tests run in their own jsdom projects, below (SPEC-CLIENTS §C.9). */
const react = ['tests/react/**/*.test.ts'];
const solid = ['tests/solid/**/*.test.ts'];
const exclude = ['**/node_modules/**', ...react, ...solid];
const reactProject = {
test: { include: react, environment: 'jsdom', benchmark: { include: [] } },
};
/**
* `solid-js` ships conditional exports and Node's resolver picks the server
* build, whose signals never propagate. Inlining it lets Vite resolve it with
* the browser conditions instead (SPEC-CLIENTS §C.9).
*/
const solidProject = {
ssr: { resolve: { conditions: ['browser', 'development'] } },
test: { include: solid, benchmark: { include: [] }, server: { deps: { inline: ['solid-js'] } } },
};
/**
* The bench project resolves `src/index` to the built bundle. Vite's SSR
* transform leaves `__DEV__` as a global read and turns every import into a
* getter on the module object — invisible in a test, a multiple in a
* per-entity loop. `npm run bench` builds first.
*/
const bundle = [
{
find: /^(\.\.\/)+src\/index$/,
replacement: fileURLToPath(new URL('./dist/index.js', import.meta.url)),
},
];
export default defineConfig({
test: {
projects: [
{
// Source with dev assertions enabled; also the project that runs the
// heap-delta allocation checks (SPEC §12.2).
define: { __DEV__: 'true' },
test: {
name: 'dev',
include,
exclude,
benchmark: { include: [] },
// `globalThis.gc` for the heap-delta assertions — workers do not
// inherit the parent process's V8 flags, so pass it through here.
pool: 'forks',
execArgv: ['--expose-gc'],
},
},
{
// Same tests with assertions compiled out, mirroring the published build.
define: { __DEV__: 'false' },
test: {
name: 'prod',
include,
exclude,
benchmark: { include: [] },
},
},
{
// The benchmarks measure what ships, so they run with the assertions
// compiled out, like the published bundle (SPEC §12.1).
define: { __DEV__: 'false' },
resolve: { alias: bundle },
test: {
name: 'bench',
include: [],
benchmark: { include: ['bench/**/*.bench.ts'] },
},
},
{
// apecs/react over React's renderer, with and without assertions.
...reactProject,
define: { __DEV__: 'true' },
test: { ...reactProject.test, name: 'react' },
},
{
...reactProject,
define: { __DEV__: 'false' },
test: { ...reactProject.test, name: 'react-prod' },
},
{
// apecs/solid over Solid's reactive graph, with and without assertions.
...solidProject,
define: { __DEV__: 'true' },
test: { ...solidProject.test, name: 'solid' },
},
{
...solidProject,
define: { __DEV__: 'false' },
test: { ...solidProject.test, name: 'solid-prod' },
},
{
// Type-level tests only (`expectTypeOf` / `assertType`) — SPEC §11.
define: { __DEV__: 'true' },
test: {
name: 'types',
include: [],
benchmark: { include: [] },
typecheck: {
enabled: true,
only: true,
include: ['tests/**/*.test-d.ts'],
tsconfig: './tsconfig.json',
},
},
},
],
},
});