|
1 | 1 | #!/usr/bin/env bun |
2 | 2 | /** |
3 | | - * Asserts every `scripts/*.test.ts` file is collected by the scripts Vitest config. |
| 3 | + * Asserts script tests are collected by the scripts Vitest config. |
4 | 4 | * |
5 | 5 | * The root `test` script once chained a hand-maintained list of `test:*` entries, and a |
6 | 6 | * hand-maintained list silently drifts from the files on disk: a test added without a matching |
7 | 7 | * entry never runs, in CI or locally, and nothing reports it. `scripts/check-migrations-safety.test.ts` |
8 | 8 | * sat unreferenced and green for exactly that reason. `scripts/vitest.config.ts` now collects |
9 | | - * the directory by glob, so drift can only come from a file the glob does not match (a test in a |
10 | | - * subdirectory, a different suffix) or from the `test` script no longer chaining `test:scripts`. |
| 9 | + * the root and tooling directories by glob. This guard walks script subdirectories so a new |
| 10 | + * test outside those globs cannot be silently skipped. `scripts/openapi` has its own suite. |
11 | 11 | * This guard checks both by asking Vitest which files it would run. |
12 | 12 | * |
13 | 13 | * `run-audits.ts` derives its own list from the `check:*` namespace precisely so a new audit is |
@@ -57,10 +57,15 @@ const collected = new Set( |
57 | 57 | ) |
58 | 58 | ) |
59 | 59 |
|
60 | | -const onDisk = readdirSync(path.join(ROOT, 'scripts')) |
61 | | - .filter((file) => file.endsWith('.test.ts')) |
62 | | - .map((file) => `scripts/${file}`) |
63 | | - .sort() |
| 60 | +function scriptTests(directory: string): string[] { |
| 61 | + return readdirSync(path.join(ROOT, directory), { withFileTypes: true }).flatMap((entry) => { |
| 62 | + const file = `${directory}/${entry.name}` |
| 63 | + if (entry.isDirectory()) return file === 'scripts/openapi' ? [] : scriptTests(file) |
| 64 | + return entry.isFile() && /\.test\.(?:ts|mjs)$/.test(entry.name) ? [file] : [] |
| 65 | + }) |
| 66 | +} |
| 67 | + |
| 68 | +const onDisk = scriptTests('scripts').sort() |
64 | 69 |
|
65 | 70 | const orphaned = onDisk.filter((file) => !collected.has(file)) |
66 | 71 | if (orphaned.length > 0) { |
|
0 commit comments