-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathvitest.shared.mts
More file actions
140 lines (137 loc) · 4.91 KB
/
Copy pathvitest.shared.mts
File metadata and controls
140 lines (137 loc) · 4.91 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
import { playwright } from '@vitest/browser-playwright';
const CURRENT_DIR = dirname(fileURLToPath(import.meta.url));
const WORKSPACE_ROOT = resolve(CURRENT_DIR, './');
export const alias = [
// Generates resolver aliases for all packages and their plans.
...[
{ lib: 'x-charts', plans: ['pro', 'premium'] },
{ lib: 'x-chat', plans: ['headless', 'unstyled'] },
{ lib: 'x-date-pickers', plans: ['pro'] },
{ lib: 'x-tree-view', plans: ['pro'] },
{ lib: 'x-data-grid', plans: ['pro', 'premium', 'generator'] },
{ lib: 'x-scheduler', plans: ['premium'] },
{ lib: 'x-scheduler-internals', plans: ['premium'] },
{ lib: 'x-agent-tools' },
{ lib: 'x-internals' },
{ lib: 'x-internal-gestures' },
{ lib: 'x-license' },
{ lib: 'x-telemetry' },
{ lib: 'x-virtualizer' },
].flatMap((v) => {
return [
{
find: `@mui/${v.lib}`,
replacement: resolve(WORKSPACE_ROOT, `./packages/${v.lib}/src`),
},
...(v.plans ?? []).map((plan) => ({
find: `@mui/${v.lib}-${plan}`,
replacement: resolve(WORKSPACE_ROOT, `./packages/${v.lib}-${plan}/src`),
})),
];
}),
// x-charts-vendor uses a build directory structure
{
find: /^@mui\/x-charts-vendor\/(.+)$/,
replacement: resolve(WORKSPACE_ROOT, './packages/x-charts-vendor/build/$1'),
},
{
find: 'test/utils',
replacement: fileURLToPath(new URL('./test/utils', import.meta.url)),
},
];
export default defineConfig({
// If enabling babel plugins, ensure the tests in CI are stable
// https://github.com/mui/mui-x/pull/18341
plugins: [react()],
// We seem to need both this and the `env` property below to make it work.
define: {
'process.env.NODE_ENV': '"test"',
__ALLOW_TEST_LICENSES__: 'true',
},
resolve: {
alias,
},
test: {
setupFiles: [fileURLToPath(new URL('test/setupVitest.ts', import.meta.url))],
// Inline so Vite resolves @mui/material's `react-transition-group/TransitionGroupContext`
// directory import (legacy `main`/`module`, no `exports`), which native ESM rejects.
// @TODO: Remove once https://github.com/mui/material-ui/pull/48645 is merged.
server: {
deps: {
inline: [/@mui\/material/, /react-transition-group/],
},
},
// Required for some tests that contain early returns or conditional tests.
passWithNoTests: true,
benchmark: {
// Benchmarks import source modules whose exports Vite's module runner wraps
// in getters. The resulting warning is advisory and `vitest-fail-on-console`
// turns it into a failure, so silence it.
suppressExportGetterWarnings: true,
},
env: {
NODE_ENV: 'test',
},
browser: {
provider: playwright({
...(process.env.PLAYWRIGHT_SERVER_WS
? {
connectOptions: {
wsEndpoint: process.env.PLAYWRIGHT_SERVER_WS,
},
}
: {
launchOptions: {
args: [
// Enable GPU so WebGL2 is enabled in browser tests
'--enable-gpu',
],
// Required for tests which use scrollbars.
ignoreDefaultArgs: ['--hide-scrollbars'],
},
}),
}),
viewport: { width: 1280, height: 800 },
headless: true,
screenshotFailures: false,
commands: {
async resetMousePosition(ctx) {
// Move the pointer out of the page. A pointer left over the content
// makes components react to hover during unrelated tests.
await ctx.page.mouse.move(10_000, 10_000);
},
async setupCrashHandler(ctx) {
ctx.page.on('crash', (page) => {
console.error(`Browser page crashed! URL: ${page.url()}`);
});
},
},
orchestratorScripts: [
{
id: 'vitest-reload-on-error',
content: `window.addEventListener('vite:preloadError', (event) => { window.location.reload(); });`,
async: true,
},
],
},
// Disable isolation to speed up the tests.
isolate: false,
// Performance improvements for the tests.
// https://vitest.dev/guide/improving-performance.html#improving-performance
...(process.env.CI && {
// Increase the timeout for the tests due to slow CI machines.
// Tests run ~3x slower under React 19 stable than React 18 (CPU-bound,
// mostly @testing-library/user-event async timing); the slowest legitimate
// tests touch ~17s in CI, so 30s leaves no headroom for noise.
testTimeout: 60000,
// Retry failed tests up to 3 times. This is useful for flaky tests.
retry: 3,
maxWorkers: 2,
}),
exclude: ['**/*.spec.{js,ts,tsx}', '**/node_modules/**', '**/dist/**'],
},
});