(ws: WebSocket)
| 54 | } |
| 55 | |
| 56 | async 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 | |
| 91 | async function closeWebSocket(ws: WebSocket): Promise<void> { |
| 92 | if (ws.readyState === WebSocket.CLOSED) { |
no test coverage detected