mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-08 18:33:39 +02:00
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
import { createRequire } from "node:module";
|
|
import path from "node:path";
|
|
import { spawnPnpmRunner } from "./pnpm-runner.mjs";
|
|
|
|
const TRUTHY_ENV_VALUES = new Set(["1", "true", "yes", "on"]);
|
|
const require = createRequire(import.meta.url);
|
|
|
|
function isTruthyEnvValue(value) {
|
|
return TRUTHY_ENV_VALUES.has(value?.trim().toLowerCase() ?? "");
|
|
}
|
|
|
|
export function resolveVitestNodeArgs(env = process.env) {
|
|
if (isTruthyEnvValue(env.OPENCLAW_VITEST_ENABLE_MAGLEV)) {
|
|
return [];
|
|
}
|
|
|
|
return ["--no-maglev"];
|
|
}
|
|
|
|
export function resolveVitestCliEntry() {
|
|
const vitestPackageJson = require.resolve("vitest/package.json");
|
|
return path.join(path.dirname(vitestPackageJson), "vitest.mjs");
|
|
}
|
|
|
|
function main(argv = process.argv.slice(2), env = process.env) {
|
|
if (argv.length === 0) {
|
|
console.error("usage: node scripts/run-vitest.mjs <vitest args...>");
|
|
process.exit(1);
|
|
}
|
|
|
|
const child = spawnPnpmRunner({
|
|
pnpmArgs: ["exec", "node", ...resolveVitestNodeArgs(env), resolveVitestCliEntry(), ...argv],
|
|
env,
|
|
});
|
|
|
|
child.on("exit", (code, signal) => {
|
|
if (signal) {
|
|
process.kill(process.pid, signal);
|
|
return;
|
|
}
|
|
process.exit(code ?? 1);
|
|
});
|
|
|
|
child.on("error", (error) => {
|
|
console.error(error);
|
|
process.exit(1);
|
|
});
|
|
}
|
|
|
|
if (import.meta.main) {
|
|
main();
|
|
}
|