From 73b18a28ed093a94dfdc6b8353d60fea4fd88d3b Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Tue, 10 Nov 2026 07:46:45 +0800 Subject: [PATCH] test(connections): limit coverage to changed behavior Keep snapshot sharing, speed decay, bounded history, numeric sorting, and visibility regression guards. Remove unrelated clear-history and pending-delivery assertions. --- src/hooks/use-connection-data.test.ts | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/src/hooks/use-connection-data.test.ts b/src/hooks/use-connection-data.test.ts index d232cd212..efc3f62dc 100644 --- a/src/hooks/use-connection-data.test.ts +++ b/src/hooks/use-connection-data.test.ts @@ -6,7 +6,7 @@ const socket = vi.hoisted(() => ({ vi.fn< (listener: (message: { type: string; data: string }) => void) => void >(), - close: vi.fn(), + close: async () => {}, })) vi.mock('react', () => ({ @@ -53,7 +53,7 @@ const monitor = async () => { const { useConnectionData: readConnectionData } = await import( './use-connection-data' ) - const { clearClosedConnections } = readConnectionData() + readConnectionData() const [subscribe, read] = vi .mocked( useSyncExternalStore< @@ -73,7 +73,7 @@ const monitor = async () => { }) return read() } - return { send, read, listener, unsubscribe, clearClosedConnections } + return { send, listener, unsubscribe } } it('reuses unchanged snapshots and lists without notifying, including totals-only updates', async () => { @@ -124,9 +124,8 @@ it('updates traffic, decays speed to zero, and preserves immutable history throu unsubscribe() }) -it('evicts the oldest closed entries at 500 and cancels pending delivery on unsubscribe', async () => { - const { send, read, listener, unsubscribe, clearClosedConnections } = - await monitor() +it('evicts the oldest closed entries at 500 without mutating retained history', async () => { + const { send, unsubscribe } = await monitor() send(Array.from({ length: 502 }, (_, i) => connection(`${i}`))) const closed = send([]) expect(closed.closedConnections).toHaveLength(500) @@ -138,17 +137,5 @@ it('evicts the oldest closed entries at 500 and cancels pending delivery on unsu expect(evicted.closedConnections.at(-1)?.id).toBe('new-b') expect(closed.closedConnections[0].id).toBe('2') - clearClosedConnections() - expect(read().closedConnections).toEqual([]) - const calls = listener.mock.calls.length - socket.addListener.mock.calls[0][0]({ - type: 'Text', - data: JSON.stringify({ connections: [connection('pending')] }), - }) - expect(vi.getTimerCount()).toBe(1) unsubscribe() - expect(vi.getTimerCount()).toBe(0) - vi.advanceTimersByTime(1_000) - expect(listener).toHaveBeenCalledTimes(calls) - expect(socket.close).toHaveBeenCalledOnce() })