test(transport): bring the WebSocket transport to 100% line coverage - #75
Merged
Conversation
Adds the missing offline tests for src/transport/websocket: - ReconnectingWebSocket WebSocket-API surface: bufferedAmount/extensions/ protocol/binaryType getters (with and without an underlying socket) and the on* attribute handlers (assign, read back, reassign, clear, shared handler across two attributes). - The local CloseEvent fallback class: the test process now runs without a global CloseEvent (bunfig [test] preload, tests/_noCloseEvent.ts), so every module instance takes the older-runtime branch and every dispatched close event exercises the fallback; test fakes dispatch the stashed real class. - WebSocketTransport resubscribe/timeout accessor passthrough. Running the suite under the CloseEvent-less preload also works around a Bun coverage misattribution: with the default branch taken, Bun's lcov emits phantom 0-hit DA records for the module prelude (lines 12-120, incl. erased type declarations) that no execution can cover, and mixing one fallback-branch module instance into the process makes it shadow every other instance's counters. The uniform fallback profile reports the file cleanly. HL_OFFLINE=1 bun test tests/ --coverage: src/transport/websocket 970/1175 (82.6%) -> 1019/1019 (100%) DA lines, 0 unhit branches; 1262 tests, 0 fail; bun run check passes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Brings
src/transport/websocketto 100% DA line coverage (and no unhit BRDA branches) under the CI coverage command, with tests only — nosrc/changes._dispatcher.ts_events.ts_id.ts_keepAlive.ts_reconnectingSocket.ts_routing.ts_subscriptionManager.tsmod.tsWhat was added
_reconnectingSocket.test.ts— "WebSocket API surface" describe:bufferedAmount/extensions/protocol/binaryTypegetters with and without an underlying socket,binaryTypesetter propagation, and theon*attribute handlers (assign, read back identity, reassign, clear withnull, one shared handler firing for two attributes).tests/_noCloseEvent.ts+bunfig.toml[test] preload: the test process now runs without a globalCloseEvent, so everyReconnectingWebSocketmodule instance takes the local fallback class — the branch older runtimes execute in production — and every dispatched close event exercises it. A new test asserts the wrapper's close events carry the fullCloseEventshape without being instances of the runtime's class. The three test fakes that construct close events (_mock.ts,_reconnectingSocket.test.ts,perf/_helpers.ts) dispatch the stashed original viaRealCloseEvent.mod.test.ts:resubscribe/timeoutaccessor passthrough to the subscription manager and dispatcher.Notes on the Bun coverage numbers
The before/after denominators differ (1175 → 1019) because Bun's lcov emission for this file is lossy (see oven-sh/bun#9008 for the class of bug):
CloseEvent-present) module branch, Bun emits phantom 0-hit DA records for the whole module prelude (lines 12–120, including erased type declarations and comments). No execution lands hits on them — verified with import-only and dynamic-import probes — so they were uncoverable by any test.Verification
HL_OFFLINE=1 bun test tests/— 1262 tests, 1026 pass, 236 skip, 0 failsrc/transport/websocket1019/1019 DA lines, 0 unhit BRDAbun run check— format, lint, docs, types (TS5 + TS7), JSDoc sync, export sync all pass (2 pre-existing lint warnings unchanged)bun run perf— smoke-tested (the perf helper now dispatchesRealCloseEvent)