-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathvitest.config.mts
124 lines (116 loc) · 3.36 KB
/
vitest.config.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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import tsconfigPaths from 'vite-tsconfig-paths';
import type { ViteUserConfig } from 'vitest/config';
import {
coverageConfigDefaults,
defaultExclude,
defineConfig,
mergeConfig,
} from 'vitest/config';
import { testShards } from './tools/test/shards.js';
import {
getCoverageIgnorePatterns,
normalizePattern,
} from './tools/test/utils.js';
const ci = !!process.env.CI;
/**
* Generates Vitest config for sharded test run.
*
* If `TEST_SHARD` environment variable is not set,
* it falls back to the provided config.
*
* Otherwise, `fallback` value is used to determine some defaults.
*/
function configureShardingOrFallbackTo(
fallback: ViteUserConfig,
): ViteUserConfig {
const shardKey = process.env.TEST_SHARD;
if (!shardKey) {
return fallback;
}
if (!testShards[shardKey]) {
const keys = Object.keys(testShards).join(', ');
throw new Error(
`Unknown value for TEST_SHARD: ${shardKey} (possible values: ${keys})`,
);
}
const include: string[] = [];
const exclude: string[] = [...defaultExclude];
for (const [key, { matchPaths: patterns }] of Object.entries(testShards)) {
if (key === shardKey) {
const testMatchPatterns = patterns.map((pattern) => {
const filePattern = normalizePattern(pattern, '.spec.ts');
return filePattern;
});
include.push(...testMatchPatterns);
break;
}
const testMatchPatterns = patterns.map((pattern) => {
const filePattern = normalizePattern(pattern, '.spec.ts');
return `**/${filePattern}`;
});
exclude.push(...testMatchPatterns);
}
const reportsDirectory = `./coverage/shard/${shardKey}`;
return {
test: {
include,
exclude,
coverage: {
reportsDirectory,
},
},
};
}
// https://vitejs.dev/config/
export default defineConfig(() =>
mergeConfig(
{
plugins: [tsconfigPaths()],
cacheDir: ci ? '.cache/vitest' : undefined,
test: {
globals: true,
setupFiles: [
'jest-extended/all',
'expect-more-jest',
'./test/setup.ts',
'test/to-migrate.ts',
],
reporters: ci ? ['default', 'github-actions'] : ['default'],
mockReset: true,
coverage: {
provider: 'v8',
ignoreEmptyLines: true,
skipFull: !ci,
reporter: ci
? ['text-summary', 'lcovonly', 'json']
: ['text-summary', 'html', 'json'],
enabled: true,
exclude: [
...coverageConfigDefaults.exclude,
...getCoverageIgnorePatterns(),
'**/*.spec.ts', // should work from defaults
'lib/**/{__fixtures__,__mocks__,__testutil__,test}/**',
'lib/**/types.ts',
'lib/types/**',
'tools/**',
'+(config.js)',
'__mocks__/**',
// fully ignored files
'lib/config-validator.ts',
'lib/constants/category.ts',
'lib/modules/datasource/hex/v2/package.ts',
'lib/modules/datasource/hex/v2/signed.ts',
'lib/util/cache/package/redis.ts',
'lib/util/http/legacy.ts',
'lib/workers/repository/cache.ts',
],
},
},
} satisfies ViteUserConfig,
configureShardingOrFallbackTo({
test: {
exclude: [...defaultExclude, 'tools/docs/test/**/*.test.mjs'],
},
}),
),
);