|
| 1 | +// run-tests-filewise.mjs — run every test file DIRECTLY, one process per file, |
| 2 | +// with no `node --test` runner in front. |
| 3 | +// |
| 4 | +// WHY THIS EXISTS (remove when it stops being true): the Node 22.x test |
| 5 | +// runner's parent<->child IPC has a deserialization bug — under CI load the |
| 6 | +// parent throws "Unable to deserialize cloned data due to invalid or |
| 7 | +// unsupported version" out of #processRawBuffer and fails whole test files |
| 8 | +// that pass everywhere else (nodejs/node#64061; fixed by nodejs/node#64706, |
| 9 | +// which current Node 24 already ships — our Node 24 lane is green on the |
| 10 | +// plain runner — but whose 22.x backport has not been released as of |
| 11 | +// 2026-08). Running each file as a plain script executes node:test |
| 12 | +// IN-PROCESS: no runner child, no IPC, nothing to mis-deserialize, while the |
| 13 | +// one-process-per-file loop below preserves exactly the isolation the runner |
| 14 | +// gives us (fresh process, fresh env, per-file exit code). |
| 15 | +// |
| 16 | +// REVERT PATH: when a Node 22.x release carries the #64706 backport, bump the |
| 17 | +// CI floor to it and point the Node 22 lanes back at plain `npm test`. |
| 18 | +// |
| 19 | +// Semantics kept identical to `npm test`: |
| 20 | +// - files run sequentially (the suite's contract is --test-concurrency=1) |
| 21 | +// - per-test {timeout} options still apply (node:test honors them in-process) |
| 22 | +// - a wedged FILE is killed at the same 300s ceiling npm test uses per test, |
| 23 | +// scaled to the file (600s), and named loudly instead of hanging the job |
| 24 | +// - FLEETDECK_TEST_DAEMON_SCRIPT et al. pass through the environment |
| 25 | + |
| 26 | +import { spawnSync } from 'node:child_process'; |
| 27 | +import { readdirSync } from 'node:fs'; |
| 28 | +import path from 'node:path'; |
| 29 | +import { fileURLToPath } from 'node:url'; |
| 30 | + |
| 31 | +const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); |
| 32 | +const TESTS_DIR = path.join(REPO_ROOT, 'tests'); |
| 33 | + |
| 34 | +// Recursive: `node --test` discovers test files in subdirectories too |
| 35 | +// (tests/helpers/gitrepo.test.mjs), and a filewise run that silently drops a |
| 36 | +// file is exactly the vacuous-pass hazard this suite guards against — the |
| 37 | +// summary line prints the file count so a discovery regression is visible, |
| 38 | +// and the per-file `# tests` totals let CI logs be diffed against `npm test`. |
| 39 | +const files = readdirSync(TESTS_DIR, { recursive: true }) |
| 40 | + .filter(name => String(name).endsWith('.test.mjs')) |
| 41 | + .sort() |
| 42 | + .map(name => path.join('tests', String(name))); |
| 43 | + |
| 44 | +if (files.length === 0) { |
| 45 | + console.error('run-tests-filewise: no tests/*.test.mjs files found'); |
| 46 | + process.exit(1); |
| 47 | +} |
| 48 | + |
| 49 | +const failures = []; |
| 50 | +const started = Date.now(); |
| 51 | +for (const [i, file] of files.entries()) { |
| 52 | + console.log(`\n# [${i + 1}/${files.length}] ${file}`); |
| 53 | + const result = spawnSync(process.execPath, [file], { |
| 54 | + cwd: REPO_ROOT, |
| 55 | + stdio: 'inherit', |
| 56 | + env: process.env, |
| 57 | + timeout: 600_000, |
| 58 | + }); |
| 59 | + if (result.status !== 0) { |
| 60 | + const why = result.signal |
| 61 | + ? `killed by ${result.signal}${result.error?.code === 'ETIMEDOUT' ? ' (600s file watchdog)' : ''}` |
| 62 | + : `exit ${result.status}`; |
| 63 | + failures.push(`${file} — ${why}`); |
| 64 | + console.error(`# FAIL ${file} (${why})`); |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +const secs = Math.round((Date.now() - started) / 1000); |
| 69 | +console.log(`\n# filewise summary: ${files.length - failures.length}/${files.length} files passed in ${secs}s`); |
| 70 | +if (failures.length) { |
| 71 | + console.error('# failing files:'); |
| 72 | + for (const f of failures) console.error(`# ${f}`); |
| 73 | + process.exit(1); |
| 74 | +} |
0 commit comments