-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathvitest.config.ts
More file actions
74 lines (64 loc) · 2.13 KB
/
vitest.config.ts
File metadata and controls
74 lines (64 loc) · 2.13 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
import {readdirSync} from 'node:fs';
import {defineConfig} from 'vitest/config';
const {TEST_PG_MODE} = process.env;
// Find all vitest.config*.ts files up to depth 2 from repo root, skipping node_modules.
function* getProjects(): Iterable<string> {
const maxDepth = 2; // depth relative to repo root
function* walk(
basePath: string,
dirUrl: URL,
depth: number,
): Generator<string> {
const entries = readdirSync(dirUrl, {withFileTypes: true});
// Process files in this directory first
const fileNames = entries.filter(e => e.isFile()).map(e => e.name);
const configNames = fileNames.filter(name =>
/^vitest\.config.*\.ts$/.test(name),
);
const hasSuffixed = configNames.some(name =>
/^vitest\.config\.[^.]+\.ts$/.test(name),
);
for (const name of configNames) {
// Skip the root config file to avoid self-reference
if (basePath === '' && name === 'vitest.config.ts') continue;
// If any suffixed config exists in this dir, exclude the base config
if (name === 'vitest.config.ts' && hasSuffixed) continue;
// Skip bench configs — those are run separately via `npm run bench`
if (name.includes('.bench')) continue;
yield `${basePath}${name}`;
}
// Recurse into subdirectories up to max depth, skipping node_modules
for (const e of entries) {
if (!e.isDirectory()) continue;
if (e.name === 'node_modules') continue;
// Skip tsnapi — run separately via `npm run api-snapshot`
if (e.name === 'tsnapi') continue;
if (depth > 0) {
yield* walk(
`${basePath}${e.name}/`,
new URL(`${e.name}/`, dirUrl),
depth - 1,
);
}
}
}
yield* walk('', new URL('./', import.meta.url), maxDepth);
}
function filterTestName(name: string) {
if (!TEST_PG_MODE) {
return true;
}
if (TEST_PG_MODE === 'nopg') {
return !name.includes('pg-');
}
if (TEST_PG_MODE === 'pg') {
return name.includes('pg-');
}
return name.includes(TEST_PG_MODE);
}
const projects = [...getProjects()].filter(filterTestName);
export default defineConfig({
test: {
projects,
},
});