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

Function waitForWebSocketRejection

src/node/orpc/server.test.ts:56–89  ·  view source on GitHub ↗
(ws: WebSocket)

Source from the content-addressed store, hash-verified

54}
55
56async function waitForWebSocketRejection(ws: WebSocket): Promise<void> {
57 return new Promise<void>((resolve, reject) => {
58 const timeout = setTimeout(() => {
59 cleanup();
60 reject(new Error("Expected WebSocket handshake to be rejected"));
61 }, 5_000);
62
63 const onError = () => {
64 cleanup();
65 resolve();
66 };
67
68 const onClose = () => {
69 cleanup();
70 resolve();
71 };
72
73 const onOpen = () => {
74 cleanup();
75 reject(new Error("Expected WebSocket handshake to be rejected"));
76 };
77
78 const cleanup = () => {
79 clearTimeout(timeout);
80 ws.off("error", onError);
81 ws.off("close", onClose);
82 ws.off("open", onOpen);
83 };
84
85 ws.once("error", onError);
86 ws.once("close", onClose);
87 ws.once("open", onOpen);
88 });
89}
90
91async function closeWebSocket(ws: WebSocket): Promise<void> {
92 if (ws.readyState === WebSocket.CLOSED) {

Callers 1

Calls 2

rejectFunction · 0.85
cleanupFunction · 0.70

Tested by

no test coverage detected