import { spawnSync } from "node:child_process"; import { existsSync } from "node:fs"; import { fileURLToPath } from "node:url"; function assertSupportedNode(): void { const [majorText = "0", minorText = "0"] = process.versions.node.split("."); const major = Number(majorText); const minor = Number(minorText); if (major !== 24 || minor < 11) { process.stderr.write( [ `Unsupported Node.js runtime for tests: ${process.versions.node}`, "Required by package.json: >=24.11.0 <25.0.0", "Use the repository-supported Node.js runtime before running a test suite.", "", ].join("\n"), ); process.exit(1); } } assertSupportedNode(); const vitestEntry = fileURLToPath( new URL("../node_modules/vitest/vitest.mjs", import.meta.url), ); if (!existsSync(vitestEntry)) { process.stderr.write( "Vitest is not installed. Run the repository package installation first.\n", ); process.exit(1); } const testEnvironment: NodeJS.ProcessEnv = { ...process.env, NODE_ENV: "test", }; for (const key of [ "npm_config_userconfig", "npm_config_prefix", "npm_config_globalconfig", "NPM_CONFIG_USERCONFIG", "NPM_CONFIG_PREFIX", "NPM_CONFIG_GLOBALCONFIG", ]) { delete testEnvironment[key]; } const result = spawnSync( process.execPath, [vitestEntry, ...process.argv.slice(2)], { stdio: "inherit", env: testEnvironment, }, ); if (result.error) { throw result.error; } if (result.signal) { process.stderr.write(`Vitest terminated by signal ${result.signal}.\n`); process.exit(1); } process.exit(result.status ?? 1);