Skip to content

Commit 1e56f43

Browse files
committed
Refactor terminal state store tests for improved clarity and performance
- Replace custom memory storage implementation with a simplified localStorage stub. - Enhance test setup by using vi.stubGlobal for localStorage, ensuring a cleaner state before each test. - Maintain existing test functionality while streamlining the code structure.
1 parent 917bcde commit 1e56f43

1 file changed

Lines changed: 10 additions & 22 deletions

File tree

apps/web/src/terminalStateStore.test.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,21 @@
11
import { ThreadId } from "@okcode/contracts";
2-
import { beforeEach, describe, expect, it } from "vitest";
3-
import { createJSONStorage } from "zustand/middleware";
2+
import { beforeEach, describe, expect, it, vi } from "vitest";
43

54
import { selectThreadTerminalState, useTerminalStateStore } from "./terminalStateStore";
65

76
const THREAD_ID = ThreadId.makeUnsafe("thread-1");
87

9-
const memoryStorage = (() => {
10-
const store = new Map<string, string>();
11-
return {
12-
getItem: (key: string) => store.get(key) ?? null,
13-
setItem: (key: string, value: string) => {
14-
store.set(key, value);
15-
},
16-
removeItem: (key: string) => {
17-
store.delete(key);
18-
},
19-
clear: () => {
20-
store.clear();
21-
},
22-
};
23-
})();
24-
258
describe("terminalStateStore actions", () => {
269
beforeEach(() => {
27-
useTerminalStateStore.persist.setOptions({
28-
storage: createJSONStorage(() => memoryStorage),
29-
});
30-
memoryStorage.clear();
10+
const storage = {
11+
getItem: () => null,
12+
setItem: () => {},
13+
removeItem: () => {},
14+
clear: () => {},
15+
};
16+
17+
vi.stubGlobal("localStorage", storage);
18+
localStorage.clear();
3119
useTerminalStateStore.setState({ terminalStateByThreadId: {} });
3220
});
3321

0 commit comments

Comments
 (0)