MCPcopy Create free account
hub / github.com/tinyplex/tinybase / MockWebSocket

Class MockWebSocket

test/unit/synchronizers/synchronizer-ws-server.test.ts:18–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16const {createWsSynchronizer} = WsClient;
17
18class MockWebSocket {
19 OPEN = 1;
20 readyState = this.OPEN;
21 sentPayloads: string[] = [];
22 readonly #listeners: {[event: string]: ((event: any) => void)[]} = {};
23
24 addEventListener(event: string, listener: (event: any) => void): void {
25 (this.#listeners[event] ??= []).push(listener);
26 }
27
28 removeEventListener(event: string, listener: (event: any) => void): void {
29 this.#listeners[event] = (this.#listeners[event] ?? []).filter(
30 (testListener) => testListener != listener,
31 );
32 }
33
34 send(payload: string): void {
35 this.sentPayloads.push(payload);
36 }
37
38 receive(payload: string): void {
39 (this.#listeners.message ?? []).forEach((listener) =>
40 listener({data: payload}),
41 );
42 }
43
44 close(): void {
45 this.readyState = 3;
46 }
47}
48
49const getFragmentGroup = (
50 payloads: string[],

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…