Skip to content

Commit e6fdd5a

Browse files
committed
fix(ci): bind script coverage to the executed runner
1 parent bee4c44 commit e6fdd5a

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎scripts/check-script-test-coverage.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,25 @@ describe('script collection command', () => {
5858
expect(valid.status, valid.stderr).toBe(0)
5959
expect(valid.stdout).toContain('4 script tests collected')
6060

61+
const manifestPath = path.join(fixture, 'package.json')
62+
const originalManifest = readFileSync(manifestPath, 'utf8')
63+
for (const command of [
64+
'echo tests-disabled',
65+
'vitest run --config scripts/alternate.config.ts',
66+
'vitest run --config scripts/vitest.config.ts scripts/nested/check.test.ts',
67+
]) {
68+
writeFileSync(
69+
manifestPath,
70+
JSON.stringify({ scripts: { test: 'bun run test:scripts', 'test:scripts': command } })
71+
)
72+
const disabled = run()
73+
expect.soft(disabled.status, command).toBe(1)
74+
expect
75+
.soft(disabled.stderr, command)
76+
.toContain('test:scripts must run the complete scripts')
77+
}
78+
writeFileSync(manifestPath, originalManifest)
79+
6180
const config = path.join(fixture, 'scripts/vitest.config.ts')
6281
writeFileSync(
6382
config,

‎scripts/check-script-test-coverage.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* entry never runs, in CI or locally, and nothing reports it. `scripts/check-migrations-safety.test.ts`
88
* sat unreferenced and green for exactly that reason. `scripts/vitest.config.ts` now collects
99
* 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`.
11-
* This guard checks both by asking Vitest which files it would run.
10+
* subdirectory, a different suffix) or from the test commands no longer running that config.
11+
* This guard checks the command contract and asks Vitest which files it would run.
1212
*
1313
* `run-audits.ts` derives its own list from the `check:*` namespace precisely so a new audit is
1414
* picked up by default, so this guard registers itself simply by being named `check:*` — it cannot
@@ -20,6 +20,8 @@ import { localBin } from './local-bin'
2020

2121
const ROOT = path.resolve(import.meta.dir, '..')
2222
const SUB_SCRIPT_PATTERN = /bun run ([\w:-]+)/g
23+
const SCRIPTS_TEST_CONFIG = 'scripts/vitest.config.ts'
24+
const SCRIPTS_TEST_COMMAND = `vitest run --config ${SCRIPTS_TEST_CONFIG}`
2325

2426
const manifest = await Bun.file(path.join(ROOT, 'package.json')).json()
2527
const commands = manifest.scripts as Record<string, string>
@@ -42,8 +44,14 @@ if (!reachableScripts('test').has('test:scripts')) {
4244
process.exit(1)
4345
}
4446

47+
// Keep collection tied to the actual runner; filters or another config can silently skip tests.
48+
if (commands['test:scripts']?.trim() !== SCRIPTS_TEST_COMMAND) {
49+
console.error(`test:scripts must run the complete scripts Vitest config: ${SCRIPTS_TEST_COMMAND}`)
50+
process.exit(1)
51+
}
52+
4553
const listed = Bun.spawnSync(
46-
[localBin('vitest'), 'list', '--json', '--filesOnly', '--config', 'scripts/vitest.config.ts'],
54+
[localBin('vitest'), 'list', '--json', '--filesOnly', '--config', SCRIPTS_TEST_CONFIG],
4755
{
4856
cwd: ROOT,
4957
}

0 commit comments

Comments
 (0)