forked from mui/base-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.shared.mts
More file actions
67 lines (58 loc) · 1.7 KB
/
vitest.shared.mts
File metadata and controls
67 lines (58 loc) · 1.7 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
import { resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { type UserWorkspaceConfig } from 'vitest/config';
// eslint-disable-next-line import/extensions
import viteConfig from '@base-ui-components/monorepo-tests/vite.shared.config.mjs';
const CURRENT_DIR = dirname(fileURLToPath(import.meta.url));
const WORKSPACE_ROOT = resolve(CURRENT_DIR, './');
const environment = process.env.VITEST_ENV;
type BrowserModeConfig = (UserWorkspaceConfig['test'] & {})['browser'];
const supportedBrowsers = ['chromium', 'webkit', 'firefox'];
function getBrowserConfig(): BrowserModeConfig {
if (
!!environment &&
(supportedBrowsers.includes(environment) || environment === 'all-browsers')
) {
const commonConfig = {
enabled: true,
provider: 'playwright',
screenshotFailures: false,
};
if (environment === 'all-browsers') {
return {
...commonConfig,
headless: true,
instances: supportedBrowsers.map((browser) => ({ browser })),
};
}
if (supportedBrowsers.includes(environment)) {
return {
...commonConfig,
headless: true,
instances: [{ browser: environment }],
};
}
}
return undefined;
}
const config: UserWorkspaceConfig = {
test: {
exclude: ['node_modules', 'build', '**/*.spec.*'],
globals: true,
setupFiles: [resolve(WORKSPACE_ROOT, './test/setupVitest.ts')],
environment: 'jsdom',
environmentOptions: {
jsdom: {
pretendToBeVisual: true,
url: 'http://localhost',
},
},
browser: getBrowserConfig(),
env: {
VITEST: 'true',
},
retry: 1,
},
resolve: viteConfig.resolve,
};
export default config;