web/test/airlock-stub.ts20 lines · 810 bytes
| 1 | // First import of airlock-selftest.ts: sets the URL to the live mode (no ?rpc=, so the real Sepolia settings are |
| 2 | // tested) before runtime.ts reads it, and swaps WebSocket for a stand-in that never connects. The test answers |
| 3 | // JSON-RPC with its own fake fetch, so nothing leaves the machine. |
| 4 | const g = globalThis as unknown as Record<string, unknown> |
| 5 | g.location = { search: '?mode=airlock', href: 'http://localhost/?mode=airlock' } |
| 6 | g.window = globalThis |
| 7 | class NoSocket { |
| 8 | static opened: string[] = [] |
| 9 | onopen: (() => void) | null = null |
| 10 | onmessage: ((ev: { data: string }) => void) | null = null |
| 11 | onclose: (() => void) | null = null |
| 12 | onerror: (() => void) | null = null |
| 13 | constructor(url: string) { |
| 14 | NoSocket.opened.push(url) |
| 15 | } |
| 16 | send() {} |
| 17 | close() {} |
| 18 | } |
| 19 | g.WebSocket = NoSocket |
| 20 | export { NoSocket } |