Repository navigation
Expand file tree
/
Copy pathvitest.config.ts
More file actions
117 lines (113 loc) · 3.2 KB
/
Copy pathvitest.config.ts
File metadata and controls
117 lines (113 loc) · 3.2 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
117
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
import { playwright } from '@vitest/browser-playwright';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const aliasEntries = [
{ find: '~', replacement: path.resolve(__dirname, './') },
{ find: '@components', replacement: path.resolve(__dirname, './components') },
{ find: '@utilities', replacement: path.resolve(__dirname, './utilities') },
{ find: '@types', replacement: path.resolve(__dirname, './types') },
];
const resolve = {
// Force a single copy of React/ReactDOM. `react-highlighter-ts` declares
// `react@^17` as a hard dependency (not a peer). A package.json `overrides`
// entry now forces it onto the root React 19 (no nested copy), and deduping
// keeps a single React instance regardless.
dedupe: ['react', 'react-dom'],
alias: aliasEntries,
};
export default defineConfig({
plugins: [react()],
resolve,
test: {
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
exclude: [
'node_modules/',
'dist/',
'**/__docs__/**',
'**/__examples__/**',
'**/*.d.ts',
'vite.config.ts',
'vitest.config.ts',
'vitest.setup.ts',
'vitest.setup.browser.ts',
],
},
// Two projects:
// - `unit` : the fast jsdom suite (the vast majority of tests).
// - `browser` : a small suite of `*.browser.test.*` files that need a real
// browser — focus traversal and text-truncation measurement
// — which jsdom cannot provide.
projects: [
{
extends: true,
test: {
name: 'unit',
globals: true,
environment: 'jsdom',
setupFiles: './vitest.setup.ts',
include: [
'components/**/__tests__/*.{test,spec}.{ts,tsx,js,jsx}',
'utilities/**/__tests__/*.{test,spec}.{ts,tsx,js,jsx}',
],
// Browser-only specs live alongside as `*.browser.test.*`; keep
// them out of the jsdom run.
exclude: [
'**/node_modules/**',
'**/dist/**',
'**/*.browser.test.{ts,tsx,js,jsx}',
],
},
},
{
extends: true,
// Node-only tests for repo tooling in `scripts/` (they spawn git).
test: {
name: 'scripts',
environment: 'node',
include: ['scripts/__tests__/*.test.mjs'],
testTimeout: 30000,
},
},
{
extends: true,
// Pre-bundle the component runtime deps so the browser optimizer does
// not discover them mid-run and reload the page (which flakes tests).
optimizeDeps: {
include: [
'react',
'react-dom',
'react-dom/client',
'react/jsx-dev-runtime',
'@floating-ui/dom',
'classnames',
'dequal',
'nanoid',
'prop-types',
'react-modal',
'warning',
'lodash.reject',
'memoize-one',
],
},
test: {
name: 'browser',
globals: true,
setupFiles: './vitest.setup.browser.ts',
include: ['components/**/__tests__/*.browser.test.{ts,tsx,js,jsx}'],
exclude: ['**/node_modules/**', '**/dist/**'],
browser: {
enabled: true,
provider: playwright(),
headless: true,
instances: [{ browser: 'chromium' }],
},
},
},
],
},
});