import { spawnSync } from 'node:child_process'; import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; const scriptPath = fileURLToPath(import.meta.url); const serverRoot = path.dirname(scriptPath); const repoRoot = path.resolve(serverRoot, '..'); const bundledNodePath = path.join( repoRoot, '.tools', 'node-v22.22.2-win-x64', process.platform === 'win32' ? 'node.exe' : 'bin/node', ); const runtimeNodePath = fs.existsSync(bundledNodePath) ? bundledNodePath : process.execPath; function collectTestFiles(dirPath) { const entries = fs.readdirSync(dirPath, { withFileTypes: true }); const testFiles = []; for (const entry of entries) { const fullPath = path.join(dirPath, entry.name); if (entry.isDirectory()) { testFiles.push(...collectTestFiles(fullPath)); continue; } if (entry.isFile() && entry.name.endsWith('.test.ts')) { testFiles.push(path.relative(serverRoot, fullPath)); } } return testFiles.sort(); } const testFiles = collectTestFiles(path.join(serverRoot, 'src')); if (testFiles.length === 0) { console.error('No test files found under server-node/src'); process.exit(1); } const result = spawnSync( runtimeNodePath, ['--test', '--test-concurrency=1', '--import', 'tsx', ...testFiles], { cwd: serverRoot, stdio: 'inherit', }, ); process.exit(result.status ?? 1);