testing/transports/ws_client.ts view source
(method: string): (msg: unknown) => boolean Predicate matching a JSON-RPC notification with the given method name.
method
stringreturns
(msg: unknown) => boolean Shared WebSocket client surface for cross-backend tests.
WsClient is the interface every in-process or cross-process WS test
driver implements — send / request / close / messages /
wait_for. Two impls today:
- In-process — create_ws_test_harness in ../ws_round_trip.ts.
Drives register_action_ws against a fake Hono upgrade so the
dispatcher's full path runs without the wire upgrade.
- Cross-process — create_ws_transport in ./ws_transport.ts.
Wraps the native WebSocket upgrade against a real running binary,
threading the session cookie captured by FetchTransport.
Wire-frame types + predicates also live here so both impls (and every shared assertion helper) reference one source.
8 declarations
testing/transports/ws_client.ts view source
(method: string): (msg: unknown) => boolean Predicate matching a JSON-RPC notification with the given method name.
methodstring(msg: unknown) => boolean testing/transports/ws_client.ts view source
<P>(method: string, match: (params: P) => boolean): (msg: unknown) => msg is JsonrpcNotificationFrame<P> Type-guard combinator: match a notification whose typed params satisfies
match. Collapses the common test pattern of casting msg to
JsonrpcNotificationFrame<P> in every predicate body.
const match_roster_for = (id: Uuid) =>
is_notification_with<RosterChangedParams>(
WORLD_METHODS.roster_changed,
(params) => params.character_id === id && !params.removed,
);
const roster = await client.wait_for(match_roster_for(char_id));methodstringmatch(params: P) => boolean(msg: unknown) => msg is JsonrpcNotificationFrame<P> testing/transports/ws_client.ts view source
(id: string | number): (msg: unknown) => boolean Predicate matching a JSON-RPC response frame (success or error) for the given request id.
idstring | number(msg: unknown) => boolean testing/transports/ws_client.ts view source
JsonrpcErrorResponseFrame<D> Dunknownjsonrpctypeof JSONRPC_VERSIONidnumber | stringerror{code: number; message: string; data?: D}testing/transports/ws_client.ts view source
JsonrpcNotificationFrame<P> Punknownjsonrpctypeof JSONRPC_VERSIONmethodstringparamsPtesting/transports/ws_client.ts view source
JsonrpcSuccessResponseFrame<R> Runknownjsonrpctypeof JSONRPC_VERSIONidnumber | stringresultRtesting/transports/ws_client.ts view source
1000 Default wait-for timeout shared across in-process + cross-process
impls. Tunable per-call via the timeout_ms parameter.
testing/transports/ws_client.ts view source
WsClient A test WS client: send requests, inspect / await incoming messages.
sendSend a JSON-RPC message (request or notification) to the server.
(message: unknown) => Promise<void>requestSend a JSON-RPC request and await its response. Resolves with the
result; throws with a useful message (code, text, and any data
payload) on an error frame — without this, asserting on
result.foo for a failed request throws
Cannot read property 'foo' of undefined, hiding the real cause.
Use send + wait_for(is_response_for(id)) directly when the test
needs to assert on the error frame itself.
<R = unknown>(
id: number | string,
method: string,
params: unknown,
timeout_ms?: number,
) => Promise<R>closeClose the connection. Returns a promise that resolves once the
transport's own cleanup (and any on_socket_close for the
in-process driver) has completed — tests that assert on post-close
state should await.
(code?: number, reason?: string) => Promise<void>messagesEvery message the server has sent, in arrival order.
ReadonlyArray<unknown>wait_forWait until a message satisfies predicate. Matches are checked
against already-received messages first, then new arrivals until
the timeout (defaults to WS_CLIENT_DEFAULT_TIMEOUT_MS).
When predicate is a type guard (e.g. is_notification_with<P>),
the result is narrowed automatically and callers don't need to
spell <JsonrpcNotificationFrame<P>> on the call site.
{
<T>(predicate: (msg: unknown) => msg is T, timeout_ms?: number): Promise<T>;
// eslint-disable-next-line @typescript-eslint/unified-signatures
<T = unknown>(predicate: (msg: unknown) => boolean, timeout_ms?: number): Promise<T>;
}