-
Notifications
You must be signed in to change notification settings - Fork 9
/
vitest.config.ts
73 lines (60 loc) · 1.91 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
/// <reference types="vitest" />
/// <reference types="vite/client" />
// TODO: much of this may be a good candidate for sharing from this internal package!
import type { CollectionValues } from '@getodk/common/types/collections/CollectionValues.ts';
import { defineConfig } from 'vitest/config';
export default defineConfig(() => {
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 {
esbuild: {
sourcemap: true,
target: 'esnext',
},
optimizeDeps: {
esbuildOptions: {
target: 'esnext',
},
force: true,
},
test: {
browser: {
enabled: BROWSER_ENABLED,
name: BROWSER_NAME!,
provider: 'playwright',
headless: true,
screenshotFailures: false,
},
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,
exclude: ['e2e/**/*'],
reporters: process.env.GITHUB_ACTIONS ? ['default', 'github-actions'] : 'default',
},
};
});