import fs from "fs"; import { spawnSync } from "child_process"; import path from "path"; const testDir = path.resolve(process.argv[2] || "tests/integration"); let files = []; if (fs.existsSync(testDir)) { files = fs .readdirSync(testDir) .filter((f) => f.endsWith(".test.ts")) .map((f) => path.join(testDir, f)) .sort(); } if (files.length === 0) { console.error("Error: Zero integration test files discovered."); process.exit(1); } const results = []; let anyFailed = false; for (const file of files) { const displayFile = path.relative(process.cwd(), file) || file; console.log(`\n=== Running ${displayFile} ===`); const childEnv = { ...process.env }; delete childEnv.NODE_TEST_CONTEXT; const child = spawnSync( process.execPath, ["--import", "tsx", "--test", file], { stdio: "inherit", env: childEnv, }, ); const exitCode = child.status ?? 1; results.push({ file: displayFile, exitCode }); if (child.error) { console.error(`Failed to launch ${displayFile}: ${child.error.message}`); } if (exitCode !== 0) { anyFailed = true; } } console.log("\n=== Integration Tests Summary ==="); let passed = 0; let failed = 0; for (const res of results) { if (res.exitCode === 0) { console.log(`PASS: ${res.file}`); passed++; } else { console.log(`FAIL: ${res.file} (exit code ${res.exitCode})`); failed++; } } console.log( `\nDiscovered: ${files.length}, Executed: ${results.length}, Passed: ${passed}, Failed: ${failed}`, ); if (files.length !== results.length) { console.error( "Fatal: Number of executed tests does not match number of discovered tests!", ); process.exit(1); } if (anyFailed) { process.exit(1); }