Skip to content

dart_node_ws: Add actual WebSocket server/client interaction tests #43

@MelbourneDeveloper

Description

@MelbourneDeveloper

Problem

packages/dart_node_ws/test/ws_test.dart has a literal TODO comment on line 11:

//TODO: we need actual web socket server/client interaction tests here.

The existing tests only cover:

  • WebSocketReadyState enum values (connecting=0, open=1, closing=2, closed=3)
  • createWebSocketServer basic instantiation (port assignment, close callback)
  • onConnection handler registration (no actual connection)

Zero tests for: message sending, message receiving, close events, error handling, JSON messaging, or any real client↔server interaction.

What's Needed

The dart_node_ws package needs actual interaction tests that verify:

  • Client connects to server and server receives the connection
  • Client sends a message and server receives it
  • Server sends a message and client receives it
  • JSON message round-trip (sendJson / onMessage parsing)
  • Client close triggers server close event with code/reason
  • Server close triggers client close event
  • Error handler fires on connection errors
  • Multiple concurrent clients

A test_server.dart helper already exists at packages/dart_node_ws/test/test_server.dart with echo/JSON support that could be leveraged.

CI Coverage Consideration

The CI workflow (.github/workflows/ci.yml via tools/test.sh) runs dart_node_ws tests as a Tier 2 Node package. Currently this only exercises the shallow unit tests above.

However, other test suites already use dart_node_ws as part of integration tests:

  • examples/backend/ runs a WebSocketService that uses dart_node_ws for real-time task broadcasting
  • examples/frontend/test/web_app_test.dart tests WebSocket-driven UI updates (via mocked browser WebSocket)

These integration tests in other packages should count toward dart_node_ws coverage in CI. The CI pipeline should be updated to aggregate coverage from downstream consumers that exercise dart_node_ws code paths, not just the package's own test directory.

References

  • packages/dart_node_ws/test/ws_test.dart - current tests (line 11 TODO)
  • packages/dart_node_ws/test/test_server.dart - existing test server helper
  • packages/dart_node_ws/lib/src/websocket_types.dart - types/API surface to test
  • packages/dart_node_ws/lib/src/websocket_server.dart - server factory to test
  • examples/backend/lib/services/websocket_service.dart - real-world usage
  • tools/test.sh - CI test runner

Metadata

Metadata

Assignees

No one assigned

    Labels

    testingTest coverage and test infrastructure

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions