-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathvitest.config.ts
98 lines (82 loc) · 2.45 KB
/
vitest.config.ts
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
/// <reference types="vitest" />
/// <reference types="vite/client" />
import type { CollectionValues } from '@getodk/common/types/collections/CollectionValues.ts';
import { resolve } from 'path';
import { defineConfig } from 'vitest/config';
export default defineConfig(({ mode }) => {
let include: string[];
let exclude: string[];
const isBenchmark = mode === 'benchmark';
if (isBenchmark) {
include = ['./benchmark/**/*.bench.ts'];
exclude = ['./src/**/*', './test/**/*'];
} else {
include = ['./test/**/*.test.ts'];
exclude = ['./src/**/*', './benchmark/**/*'];
}
const supportedBrowsers = new Set(['chromium', 'firefox', 'webkit'] as const);
type SupportedBrowser = CollectionValues<typeof supportedBrowsers>;
const isSupportedBrowser = (browserName: string): browserName is SupportedBrowser =>
supportedBrowsers.has(browserName as SupportedBrowser);
const BROWSER_NAME = (() => {
const envBrowserName = process.env.BROWSER_NAME;
if (envBrowserName == null) {
return null;
}
if (isSupportedBrowser(envBrowserName)) {
return envBrowserName;
}
throw new Error(`Unsupported browser: ${envBrowserName}`);
})();
const BROWSER_ENABLED = BROWSER_NAME != null;
const TEST_ENVIRONMENT = BROWSER_ENABLED ? 'node' : 'jsdom';
return {
build: {
target: false as const,
},
esbuild: {
sourcemap: true,
target: 'esnext',
},
optimizeDeps: {
esbuildOptions: {
target: 'esnext',
},
exclude: ['@getodk/xforms-engine'],
force: true,
},
resolve: {
alias: {
'@getodk/xforms-engine': resolve(__dirname, '../xforms-engine/src/index.ts'),
},
conditions: ['solid', 'browser', 'development'],
},
test: {
browser: {
enabled: BROWSER_ENABLED,
name: BROWSER_NAME!,
provider: 'playwright',
headless: true,
screenshotFailures: false,
},
include,
exclude,
deps: {
optimizer: {
web: {
// Prevent loading multiple instances of Solid. This deviates from
// most of the recommendations provided by Solid and related tooling,
// as Vitest's interfaces have since changed. But it does seem to be
// the appropriate solution (at least for our usage).
exclude: ['solid-js'],
},
},
moduleDirectories: ['node_modules', '../../node_modules'],
},
environment: TEST_ENVIRONMENT,
globals: false,
setupFiles: ['./src/vitest/setup.ts'],
reporters: process.env.GITHUB_ACTIONS ? ['default', 'github-actions'] : 'default',
},
};
});