import { test } from 'node:test'; import assert from 'node:assert/strict'; import { FakeTransport } from '../helpers/fake-transport.ts'; test('FakeTransport:connect 后异步触发 onOpen', async () => { const t = new FakeTransport(); let opened = false; t.onOpen(() => { opened = true; }); t.connect('ws://x'); await t.flush(); assert.equal(opened, true); }); test('FakeTransport:客户端 send 进入 sent 队列;serverPush 触发 onMessage', async () => { const t = new FakeTransport(); const got: string[] = []; t.onMessage((f) => got.push(f)); t.connect('ws://x'); await t.flush(); t.send('hello'); assert.deepEqual(t.sent, ['hello']); t.serverPush('world'); await t.flush(); assert.deepEqual(got, ['world']); }); test('FakeTransport:close 触发 onClose', async () => { const t = new FakeTransport(); let closed = false; t.onClose(() => { closed = true; }); t.connect('ws://x'); await t.flush(); t.close(); await t.flush(); assert.equal(closed, true); });