mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 01:00:21 +00:00
fix(test): clean up vitest child process groups
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { createRequire } from "node:module";
|
||||
import path from "node:path";
|
||||
import { spawnPnpmRunner } from "./pnpm-runner.mjs";
|
||||
import {
|
||||
installVitestProcessGroupCleanup,
|
||||
shouldUseDetachedVitestProcessGroup,
|
||||
} from "./vitest-process-group.mjs";
|
||||
|
||||
const TRUTHY_ENV_VALUES = new Set(["1", "true", "yes", "on"]);
|
||||
const require = createRequire(import.meta.url);
|
||||
@@ -22,18 +26,28 @@ export function resolveVitestCliEntry() {
|
||||
return path.join(path.dirname(vitestPackageJson), "vitest.mjs");
|
||||
}
|
||||
|
||||
export function resolveVitestSpawnParams(env = process.env, platform = process.platform) {
|
||||
return {
|
||||
env,
|
||||
detached: shouldUseDetachedVitestProcessGroup(platform),
|
||||
};
|
||||
}
|
||||
|
||||
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 spawnParams = resolveVitestSpawnParams(env);
|
||||
const child = spawnPnpmRunner({
|
||||
pnpmArgs: ["exec", "node", ...resolveVitestNodeArgs(env), resolveVitestCliEntry(), ...argv],
|
||||
env,
|
||||
...spawnParams,
|
||||
});
|
||||
const teardownChildCleanup = installVitestProcessGroupCleanup({ child });
|
||||
|
||||
child.on("exit", (code, signal) => {
|
||||
teardownChildCleanup();
|
||||
if (signal) {
|
||||
process.kill(process.pid, signal);
|
||||
return;
|
||||
@@ -42,6 +56,7 @@ function main(argv = process.argv.slice(2), env = process.env) {
|
||||
});
|
||||
|
||||
child.on("error", (error) => {
|
||||
teardownChildCleanup();
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user