testing/transports/ws_raw_client.ts

A raw-socket WebSocket client for tests that need to misbehave, or to control exactly which bytes reach the server when.

A client library answers a close frame itself and sends nothing until its open event, so two server behaviors can't be reached through one: what the server does with a client that withholds its close frame, and what it does with frames that arrive with the handshake, before the connection can have been admitted. This speaks just enough RFC 6455 over node:net to do both — the upgrade request, masked client text frames, and unmasked server frames — and deliberately never replies to a close.

Small frames only (payloads under 64 KiB, unfragmented), which is all the JSON-RPC traffic the suites send.

view source

Declarations
#

8 declarations

connect_raw_ws
#

testing/transports/ws_raw_client.ts view source

(options: RawWsConnectOptions): Promise<RawWsClient> import {connect_raw_ws} from '@fuzdev/fuz_app/testing/transports/ws_raw_client.js';

Upgrade a raw TCP socket to a WebSocket.

Resolves once the server answers 101; rejects on any other status or a connection error.

options

returns

Promise<RawWsClient>

throws

  • Error - when the upgrade is refused or the connection fails

is_raw_ws_close
#

raw_ws_close_code
#

testing/transports/ws_raw_client.ts view source

(frame: RawWsFrame): number | null import {raw_ws_close_code} from '@fuzdev/fuz_app/testing/transports/ws_raw_client.js';

The close code a close frame carries, or null when it carries none.

frame

returns

number | null

RAW_WS_OPCODE_CLOSE
#

RAW_WS_OPCODE_TEXT
#

RawWsClient
#

testing/transports/ws_raw_client.ts view source

RawWsClient import type {RawWsClient} from '@fuzdev/fuz_app/testing/transports/ws_raw_client.js';

A WebSocket client that sends frames and never answers a close.

frames

Every frame the server sent, in order.

type RawWsFrame[]

send_text

Send one masked text frame.

type (text: string): void

text

type string
returns void

wait_for

Resolves with the first frame, already received or not, matching predicate.

type (predicate: (frame: RawWsFrame) => boolean, timeout_ms?: number | undefined): Promise<RawWsFrame>

predicate

type (frame: RawWsFrame) => boolean

timeout_ms?

type number
optional
returns Promise<RawWsFrame>

destroy

Drop the TCP connection, with no close handshake.

type (): void

returns void

RawWsConnectOptions
#

testing/transports/ws_raw_client.ts view source

RawWsConnectOptions import type {RawWsConnectOptions} from '@fuzdev/fuz_app/testing/transports/ws_raw_client.js';

Options for connect_raw_ws.

port

type number

hostname?

type string

default '127.0.0.1'

path

The WebSocket endpoint path (e.g. /api/ws).

type string

headers?

Extra upgrade request headers — Cookie, Origin.

type Record<string, string>

pipelined?

Text frames to write in the same TCP write as the upgrade request, so they are in the server's hands before the handshake is answered — and so before the connection can have been admitted.

type readonly string[]

RawWsFrame
#

Depends on
#

Imported by
#