Skip to content
This repository was archived by the owner on Nov 9, 2026. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions web/test/net-trouble.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ const entry = `export { attachNet } from './web/src/net/index.ts'; export * as P
const js = (await esbuild.build({ stdin: { contents: entry, resolveDir: ROOT, loader: 'ts' }, bundle: true, format: 'esm', write: false, platform: 'neutral' })).outputFiles[0].text;
const { attachNet, P } = await import('data:text/javascript;base64,' + Buffer.from(js).toString('base64'));

// node's own WebSocket reports a refused handshake with an error and no close; a browser's (and ws's) closes it too
globalThis.WebSocket = WsClient;
// node's own WebSocket reports a refused handshake with an error and no close; a browser's (and ws's) closes it too.
// ws reports a close during the handshake as an 'error' event, thrown when nothing listens, and the page's close()
// takes its handlers off first (a browser's just closes): the listener keeps a link closed mid-reconnect from failing
// a test
globalThis.WebSocket = class extends WsClient { constructor(...a) { super(...a); this.on('error', () => {}); } };
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
const until = async (f, what, ms = 8000) => { const t0 = Date.now(); while (!f()) { if (Date.now() - t0 > ms) throw new Error(`${what}: timed out`); await sleep(10); } };

Expand Down
Loading