-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvitest.config.shared.mts
51 lines (46 loc) · 1.22 KB
/
vitest.config.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
import * as vitest from 'vitest/config';
const isCI = process.env['CI'] === 'true';
export const base: vitest.ViteUserConfig = {
test: {
include: ['src/**/*.test.{ts,tsx}', 'test/**/*.test.{ts,tsx}'],
coverage: {
thresholds: {
lines: 100,
branches: 100,
},
provider: 'istanbul',
include: ['src/**/*.ts', 'src/**/*.tsx'],
exclude: ['**/*.test.ts', '**/*.test.tsx'],
},
minWorkers: isCI ? 1 : undefined,
maxWorkers: isCI ? 6 : undefined,
reporters: isCI ? ['verbose', 'junit'] : [],
outputFile: isCI ? 'reports/junit.xml' : undefined,
},
};
/**
* Merge two objects recursively. Merges only objects, not arrays, strings, etc.
* If the two values cannot be merged, then `b` is used.
*/
function merge(a: any, b: any): any {
if (
typeof a !== 'object' ||
typeof b !== 'object' ||
!a ||
!b ||
Array.isArray(a) ||
Array.isArray(b)
) {
return b;
}
const result: any = { ...a };
for (const [key, value] of Object.entries(b)) {
result[key] = merge(a[key], value);
}
return result;
}
export function defineConfig(
config: vitest.ViteUserConfig = {}
): vitest.ViteUserConfig {
return vitest.defineConfig(merge(base, config));
}