MCPcopy
hub / github.com/coder/mux / TestBridge

Class TestBridge

vscode/src/webview/createVscodeOrpcLink.test.ts:7–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5import type { VscodeBridge } from "./vscodeBridge";
6
7class TestBridge implements VscodeBridge {
8 traceId = "test";
9 startedAtMs = 0;
10
11 readonly sent: WebviewToExtensionMessage[] = [];
12 throwOnPostMessage = false;
13
14 private readonly listeners = new Set<(data: unknown) => void>();
15
16 postMessage(payload: WebviewToExtensionMessage): void {
17 this.sent.push(payload);
18
19 if (this.throwOnPostMessage) {
20 throw new Error("postMessage failed");
21 }
22 }
23
24 onMessage(handler: (data: unknown) => void): () => void {
25 this.listeners.add(handler);
26 return () => {
27 this.listeners.delete(handler);
28 };
29 }
30
31 debugLog(_message: string, _data?: unknown): void {
32 // no-op for tests
33 }
34
35 emit(data: unknown): void {
36 for (const listener of this.listeners) {
37 listener(data);
38 }
39 }
40}
41
42function getLastSent(bridge: TestBridge, type: WebviewToExtensionMessage["type"]): WebviewToExtensionMessage {
43 const msg = [...bridge.sent].reverse().find((m) => m.type === type);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected