Файли
openidea/src/features/debugger/__tests__/watchStorage.test.ts
T
ntbang0901 49bb6b2d76 fix(debugger): keep watches per project (#3293)
Watches were one list shared by every project, so a watch added while debugging one project showed up, and usually failed to evaluate, in all the others. Each project now keeps its own list; a project without one starts from the old shared list once, since that list doesn't record which project each watch came from.

Co-authored-by: ntbang0901 <[email protected]>
2026-11-14 13:40:10 +08:00

50 рядки
1.4 KiB
TypeScript

import { beforeEach, describe, expect, it } from "vitest";
import { addWatch, loadWatches, useDebug } from "../state";
const SHARED = "openidea.debugger.watches";
const of = (root: string) => `${SHARED}:${root}`;
const watches = () => useDebug.getState().watches;
beforeEach(() => {
localStorage.clear();
loadWatches(null);
});
describe("watch storage", () => {
it("loads a project's own watches", () => {
localStorage.setItem(of("/a"), '["x"]');
loadWatches("/a");
expect(watches()).toEqual(["x"]);
});
it("starts a project from the shared list once", () => {
localStorage.setItem(SHARED, '["legacy"]');
loadWatches("/b");
expect(watches()).toEqual(["legacy"]);
expect(localStorage.getItem(of("/b"))).toBe('["legacy"]');
expect(localStorage.getItem(SHARED)).toBe('["legacy"]');
});
it("keeps projects apart", () => {
loadWatches("/a");
addWatch("y");
loadWatches("/b");
expect(watches()).not.toContain("y");
loadWatches("/a");
expect(watches()).toContain("y");
});
it("an emptied list stays empty", () => {
localStorage.setItem(SHARED, '["legacy"]');
localStorage.setItem(of("/a"), "[]");
loadWatches("/a");
expect(watches()).toEqual([]);
});
it("without a project nothing is stored", () => {
loadWatches(null);
addWatch("z");
expect(localStorage.length).toBe(0);
});
});