mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-09 19:04:30 +02:00
fix(test): isolate shared vitest home setup
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user