testing/transports/ws_transport.ts

Cross-process WebSocket transport.

Implements the shared WsClient interface (see testing/transports/ws_client.ts) over a real WebSocket upgrade against a spawned test binary. The cookie captured by the sibling FetchTransport on bootstrap is threaded onto the upgrade request so the WS session authenticates as the same account.

Uses the ws npm package — Node's native WebSocket (from undici) follows the WHATWG spec strictly and doesn't accept custom request headers on construction, so cookie-on-upgrade requires the ws package's headers option. fuz_app declares ws as an optional peerDependency — consumers wiring cross-process tests install it themselves (npm install --save-dev ws).

view source

Declarations
#

2 declarations

create_ws_transport
#

testing/transports/ws_transport.ts view source

(options: WsTransportOptions): Promise<WsClient> import {create_ws_transport} from '@fuzdev/fuz_app/testing/transports/ws_transport.js';

Build a real-upgrade WS client pinned to options.base_url + ws_path.

Resolves once the upgrade succeeds and the socket is in OPEN state; rejects if the upgrade is refused (401, allowlist rejection, network failure). Incoming messages are JSON-parsed and pushed onto the messages array; wait_for checks already-received messages first before waiting for new arrivals.

options

returns

Promise<WsClient>

throws

  • Error - if the upgrade fails (status, network) — the rejection

WsTransportOptions
#

testing/transports/ws_transport.ts view source

WsTransportOptions import type {WsTransportOptions} from '@fuzdev/fuz_app/testing/transports/ws_transport.js';

Construction options for create_ws_transport.

base_url

Base URL the binary is reachable at — e.g. http://localhost:8788. Converted to ws:// for the upgrade.

type string

readonly

ws_path

WebSocket endpoint path on the binary (e.g. /api/ws).

type string

readonly

cookies

Session cookie values (full Set-Cookie strings as FetchTransport.cookies() returns them) threaded onto the upgrade Cookie header. Without these the upgrade is anonymous and per-action auth fails on the first message.

type ReadonlyArray<string>

readonly

origin?

Origin header for the upgrade. Backends running with ALLOWED_ORIGINS=http://localhost:* accept http://localhost:<port>. Defaults to base_url — acceptable because cross-process tests always run against localhost.

type string

readonly

default_timeout_ms?

Optional per-call default for wait_for timeouts. Falls back to WS_CLIENT_DEFAULT_TIMEOUT_MS if omitted.

type number

readonly

on_request?

Optional responder for server-initiated requests (the server→client direction ActionPeer adds). Attached before the upgrade so a connect-time or on-demand peer/ping is answered as soon as it arrives. Omit for the default observe-only client — a server-initiated request is then surfaced as a normal message (today's behavior).

type WsRequestResponder

readonly

Depends on
#

Imported by
#