返回 DeepSeek-Reasonix
desktop-host-stub.test.ts
根目录 / desktop / frontend / src / __tests__ / desktop-host-stub.test.ts
1 import assert from "node:assert/strict";
2 import { installDesktopHostStub } from "./desktopHostStub";
3 import { desktopHost } from "../lib/desktopHost";
4
5 Object.defineProperty(globalThis, "window", { configurable: true, value: {} });
6 const commands: { Version: () => Promise<string>; TranscriptSnapshotForTab?: () => Promise<unknown> } = { Version: async () => "test", TranscriptSnapshotForTab: undefined };
7 const stub = installDesktopHostStub(commands);
8 assert.equal(typeof desktopHost().app?.Version, "function");
9 assert.equal(desktopHost().app?.TranscriptSnapshotForTab, undefined, "an unimplemented optional method must not advertise protocol support");
10 commands.TranscriptSnapshotForTab = async () => ({});
11 assert.equal(typeof desktopHost().app?.TranscriptSnapshotForTab, "function", "a newly installed method is discovered without reinstalling the host");
12 delete commands.TranscriptSnapshotForTab;
13 assert.equal(desktopHost().app?.TranscriptSnapshotForTab, undefined);
14 stub.uninstall();
15 console.log("desktop host stub advertises only callable commands");
16
16 lines TYPESCRIPT