// Run the repository's Node tests with bounded file-level parallelism. Each file can start CLI processes, // workers or a browser of its own. Keep the usual CPU-based default on small runners. import { spawnSync } from 'node:child_process'; import { availableParallelism } from 'node:os'; import { pathToFileURL } from 'node:url'; import path from 'node:path'; export function testArguments(args, cpus = availableParallelism()) { const explicit = args.some(arg => arg === '--test-concurrency' || arg.startsWith('--test-concurrency=')); const concurrency = Math.min(8, Math.max(1, cpus - 1)); return ['--test', ...(explicit ? [] : ['--test-concurrency=' + concurrency]), ...args]; } if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) { const result = spawnSync(process.execPath, testArguments(process.argv.slice(2)), { stdio: 'inherit' }); if (result.error) throw result.error; process.exitCode = result.status ?? 1; }