mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:50:43 +00:00
test(config): avoid module resets in pruning tests
This commit is contained in:
@@ -11,10 +11,8 @@ vi.mock("../config.js", async () => ({
|
||||
loadConfig: vi.fn().mockReturnValue({}),
|
||||
}));
|
||||
|
||||
let loadConfig: typeof import("../config.js").loadConfig;
|
||||
let clearSessionStoreCacheForTest: typeof import("./store.js").clearSessionStoreCacheForTest;
|
||||
let loadSessionStore: typeof import("./store.js").loadSessionStore;
|
||||
let saveSessionStore: typeof import("./store.js").saveSessionStore;
|
||||
import { loadConfig } from "../config.js";
|
||||
import { clearSessionStoreCacheForTest, loadSessionStore, saveSessionStore } from "./store.js";
|
||||
|
||||
let mockLoadConfig: ReturnType<typeof vi.fn>;
|
||||
|
||||
@@ -88,21 +86,17 @@ describe("Integration: saveSessionStore with pruning", () => {
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
({ loadConfig } = await import("../config.js"));
|
||||
({ clearSessionStoreCacheForTest, loadSessionStore, saveSessionStore } =
|
||||
await import("./store.js"));
|
||||
mockLoadConfig = vi.mocked(loadConfig) as ReturnType<typeof vi.fn>;
|
||||
mockLoadConfig.mockReset();
|
||||
testDir = await createCaseDir("pruning-integ");
|
||||
storePath = path.join(testDir, "sessions.json");
|
||||
savedCacheTtl = process.env.OPENCLAW_SESSION_CACHE_TTL_MS;
|
||||
process.env.OPENCLAW_SESSION_CACHE_TTL_MS = "0";
|
||||
clearSessionStoreCacheForTest();
|
||||
mockLoadConfig.mockClear();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
mockLoadConfig.mockReset();
|
||||
clearSessionStoreCacheForTest();
|
||||
if (savedCacheTtl === undefined) {
|
||||
delete process.env.OPENCLAW_SESSION_CACHE_TTL_MS;
|
||||
|
||||
Reference in New Issue
Block a user