-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathvitest.shared.mts
68 lines (59 loc) · 1.61 KB
/
vitest.shared.mts
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
import { resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { type UserWorkspaceConfig } from 'vitest/config';
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',
},
},
resolve: {
alias: {
docs: resolve(WORKSPACE_ROOT, './docs'),
},
},
};
export default config;