import { readFileSync } from "node:fs" import { spawnSync } from "node:child_process" const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")) const npmCli = process.env.npm_execpath if (!npmCli) throw new Error("Запускайте тесты через npm --prefix backend test") const profiles = pkg.scripts["test:all"].split(/\s*&&\s*/).map(command => { const match = /^npm run (test:[\w-]+(?::[\w-]+)*)$/.exec(command) if (!match || !Object.hasOwn(pkg.scripts, match[1])) throw new Error(`Неизвестный профиль тестов backend: ${command}`) return match[1] }) for (const profile of profiles) { const result = spawnSync(process.execPath, [npmCli, "run", profile], { cwd: new URL("../", import.meta.url), env: { ...process.env, NODE_ENV: "test" }, stdio: "inherit", }) if (result.error) throw result.error if (result.status !== 0) process.exit(result.status ?? 1) }