| 1 | /** Stand-in for the Workers runtime's `cloudflare:sockets` module: a unit test sets what connect() returns with setConnect. */ |
| 2 | type Connect = (address: { hostname: string; port: number } | string, options?: { secureTransport?: string; allowHalfOpen: boolean }) => Socket; |
| 3 | |
| 4 | let fake: Connect | null = null; |
| 5 | |
| 6 | export function setConnect(fn: Connect | null): void { |
| 7 | fake = fn; |
| 8 | } |
| 9 | |
| 10 | export const connect: Connect = (address, options) => { |
| 11 | if (!fake) throw new Error("this test set no fake connect()"); |
| 12 | return fake(address, options); |
| 13 | }; |