-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Expand file tree
/
Copy pathvitest.config.mts
More file actions
139 lines (130 loc) · 3.73 KB
/
Copy pathvitest.config.mts
File metadata and controls
139 lines (130 loc) · 3.73 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import type { ViteUserConfig } from 'vitest/config';
import {
coverageConfigDefaults,
defaultExclude,
defineConfig,
mergeConfig,
} from 'vitest/config';
import { testShards } from './tools/test/shards.ts';
import {
getCoverageIgnorePatterns,
normalizePattern,
} from './tools/test/utils.ts';
const ci = !!process.env.CI;
const agentHook = !!process.env.RENOVATE_AGENT_HOOK;
let reporters: string[] = ['default'];
if (ci) {
reporters = ['default', 'github-actions', 'junit'];
} else if (agentHook) {
reporters = ['minimal'];
}
/**
* 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,
outputFile: `./coverage/shard/${shardKey}/junit.xml`,
coverage: {
reportsDirectory,
},
},
};
}
// https://vitejs.dev/config/
export default defineConfig(() =>
mergeConfig(
{
resolve: { tsconfigPaths: true },
oxc: { include: /\.([cm]?ts|[jt]sx)$/ }, // Fixes .cts fixtures not being transformed
cacheDir: ci ? '.cache/vitest' : undefined,
test: {
globals: true,
setupFiles: [
'jest-extended/all',
'expect-more-jest',
'./test/setup.ts',
'test/to-migrate.ts',
],
reporters,
mockReset: true,
coverage: {
provider: 'v8',
skipFull: !ci,
reporter: ci
? ['text-summary', 'lcovonly', 'json']
: ['text-summary', '@containerbase/istanbul-reports-html', 'json'],
enabled: true,
exclude: [
...coverageConfigDefaults.exclude,
...getCoverageIgnorePatterns(),
'**/*.spec.ts', // should work from defaults
'lib/**/{__fixtures__,__mocks__,__testutil__,test}/**',
'lib/**/types.ts',
'lib/types/**',
'test/**',
'tools/**',
'+(config.js)',
'__mocks__/**',
// fully ignored files
'*.config.{mts,mjs}',
'*.json',
'lib/config-validator.ts',
'lib/constants/category.ts',
'lib/modules/datasource/hex/v2/package.ts',
'lib/modules/datasource/hex/v2/signed.ts',
'lib/util/http/legacy.ts',
'lib/workers/repository/cache.ts',
],
},
},
} satisfies ViteUserConfig,
configureShardingOrFallbackTo({
test: {
exclude: [
...defaultExclude,
'dist/**/*',
'tools/docs/test/**/*.test.mjs',
'.worktrees/**/*',
],
},
}),
),
);