(ws: WebSocket)
| 25 | } |
| 26 | |
| 27 | async function waitForWebSocketOpen(ws: WebSocket): Promise<void> { |
| 28 | await new Promise<void>((resolve, reject) => { |
| 29 | const onOpen = () => { |
| 30 | cleanup(); |
| 31 | resolve(); |
| 32 | }; |
| 33 | |
| 34 | const onError = (error: Error) => { |
| 35 | cleanup(); |
| 36 | reject(error); |
| 37 | }; |
| 38 | |
| 39 | const onClose = () => { |
| 40 | cleanup(); |
| 41 | reject(new Error("WebSocket closed before opening")); |
| 42 | }; |
| 43 | |
| 44 | const cleanup = () => { |
| 45 | ws.off("open", onOpen); |
| 46 | ws.off("error", onError); |
| 47 | ws.off("close", onClose); |
| 48 | }; |
| 49 | |
| 50 | ws.once("open", onOpen); |
| 51 | ws.once("error", onError); |
| 52 | ws.once("close", onClose); |
| 53 | }); |
| 54 | } |
| 55 | |
| 56 | async function waitForWebSocketRejection(ws: WebSocket): Promise<void> { |
| 57 | return new Promise<void>((resolve, reject) => { |
no outgoing calls
no test coverage detected