Skip to content

test(transport): bring the WebSocket transport to 100% line coverage - #75

Merged
joeblau merged 1 commit into
mainfrom
test/coverage-cov-ws
Jul 27, 2026
Merged

test(transport): bring the WebSocket transport to 100% line coverage#75
joeblau merged 1 commit into
mainfrom
test/coverage-cov-ws

Conversation

@joeblau

@joeblau joeblau commented Jul 27, 2026

Copy link
Copy Markdown

Summary

Brings src/transport/websocket to 100% DA line coverage (and no unhit BRDA branches) under the CI coverage command, with tests only — no src/ changes.

HL_OFFLINE=1 bun test tests/ --coverage --coverage-reporter=lcov --coverage-dir=coverage
File Before After
_dispatcher.ts 242/242 (100%) 242/242 (100%)
_events.ts 76/76 (100%) 76/76 (100%)
_id.ts 43/43 (100%) 43/43 (100%)
_keepAlive.ts 23/23 (100%) 23/23 (100%)
_reconnectingSocket.ts 269/461 (58.4%) 310/310 (100%)
_routing.ts 61/61 (100%) 61/61 (100%)
_subscriptionManager.ts 188/188 (100%) 188/188 (100%)
mod.ts 68/81 (84.0%) 76/76 (100%)
Total 970/1175 (82.6%) 1019/1019 (100%)

What was added

  • _reconnectingSocket.test.ts — "WebSocket API surface" describe: bufferedAmount/extensions/protocol/binaryType getters with and without an underlying socket, binaryType setter propagation, and the on* attribute handlers (assign, read back identity, reassign, clear with null, one shared handler firing for two attributes).
  • tests/_noCloseEvent.ts + bunfig.toml [test] preload: the test process now runs without a global CloseEvent, so every ReconnectingWebSocket module 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 full CloseEvent shape 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 via RealCloseEvent.
  • mod.test.ts: resubscribe / timeout accessor 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):

  • With the default (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.
  • Covering the fallback class via a query-string re-import removed the phantom block but made that second module instance shadow the counters of every other instance in the process, regressing attribution elsewhere. The uniform fallback-branch profile (this PR) reports the file cleanly and deterministically (two consecutive full-suite runs produce identical reports).

Verification

  • HL_OFFLINE=1 bun test tests/ — 1262 tests, 1026 pass, 236 skip, 0 fail
  • Coverage (two consecutive runs, identical): src/transport/websocket 1019/1019 DA lines, 0 unhit BRDA
  • bun 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 dispatches RealCloseEvent)

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.
@joeblau
joeblau merged commit 5675b80 into main Jul 27, 2026
3 of 5 checks passed
@joeblau
joeblau deleted the test/coverage-cov-ws branch July 27, 2026 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant