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 / offline-stub.ts
web/test/offline-stub.ts25 lines · 819 bytes
1// First import of offline-selftest.ts: ?mode=offline, and every way out of the machine is a trap that records the
2// attempt (fetch, WebSocket, EventSource, XMLHttpRequest). Offline playback must never touch any of them.
3const g = globalThis as unknown as Record<string, unknown>
4g.location = { search: '?mode=offline', href: 'http://localhost/?mode=offline' }
5g.window = globalThis
6export const attempts: string[] = []
7g.fetch = (url: unknown) => {
8 attempts.push(`fetch ${String(url)}`)
9 return Promise.reject(new Error('offline: no network'))
10}
11class Trap {
12 constructor(url: unknown) {
13 attempts.push(`socket ${String(url)}`)
14 }
15 send() {}
16 close() {}
17}
18g.WebSocket = Trap
19g.EventSource = Trap
20g.XMLHttpRequest = class {
21 open(_m: string, url: string) {
22 attempts.push(`xhr ${url}`)
23 }
24 send() {}
25}