fix(test): isolate shared vitest home setup

This commit is contained in:
Peter Steinberger
2026-04-07 06:32:26 +01:00
parent 2aabe0e8fd
commit e2f0ea4625
3 changed files with 50 additions and 2 deletions

View File

@@ -51,13 +51,41 @@ type SharedTestSetupOptions = {
loadProfileEnv?: boolean;
};
const SHARED_TEST_SETUP = Symbol.for("openclaw.sharedTestSetup");
type SharedTestSetupHandle = {
cleanup: () => void;
tempHome: string;
};
export function installSharedTestSetup(options?: SharedTestSetupOptions): {
cleanup: () => void;
tempHome: string;
} {
const globalState = globalThis as typeof globalThis & {
[SHARED_TEST_SETUP]?: SharedTestSetupHandle;
};
const existing = globalState[SHARED_TEST_SETUP];
if (existing) {
return existing;
}
const testEnv = withIsolatedTestHome({
loadProfileEnv: options?.loadProfileEnv,
});
installProcessWarningFilter();
return testEnv;
let cleaned = false;
const handle: SharedTestSetupHandle = {
tempHome: testEnv.tempHome,
cleanup: () => {
if (cleaned) {
return;
}
cleaned = true;
testEnv.cleanup();
},
};
globalState[SHARED_TEST_SETUP] = handle;
return handle;
}