Source mirror · commit 369512f · 2026-10-26 · MIT · canonical repo: gitlab.com/jiapunk/upgrade-airlock
git clone https://upgrade-airlock.pages.dev/source/upgrade-airlock.git
upgrade-airlock / web / test / airlock-stub.ts
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.
4const g = globalThis as unknown as Record<string, unknown>
5g.location = { search: '?mode=airlock', href: 'http://localhost/?mode=airlock' }
6g.window = globalThis
7class 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}
19g.WebSocket = NoSocket
20export { NoSocket }