import type { LogSocketFactory, LogSocketInit, LogSocketLike, WebSocketFactory, WebSocketLike } from "./socket.ts"; /** * A controllable {@link WebSocketLike} test double. It captures every frame the socket under test sends and every close code it issues, and it exposes explicit emit * methods so a test can drive the connection through its handshake, ping/pong, streaming, and teardown by hand - no real network, fully deterministic. * * Fidelity to the seam contract: `readyState` starts OPEN and flips to CLOSED on the first `close()` (or an inbound {@link TestWebSocket.emitClose}), so the socket's * teardown gate (send the namespace DISCONNECT only while OPEN) behaves exactly as it would against a real connection; `send` records the frame regardless of state so a * test can assert the exact wire sequence including any post-close send attempt. * * @category Testing */ export declare class TestWebSocket implements WebSocketLike { #private; readonly sent: string[]; readonly closeCodes: number[]; readonly url: string; /** * Construct a controllable WebSocket double. * * @param url - The connect URL the factory was asked to build. Defaults to an empty string for tests that do not assert on the URL. */ constructor(url?: string); /** * Register a listener. Mirrors the DOM `addEventListener` overloads the {@link WebSocketLike} seam declares; the matching `emit*` method dispatches to every * registered listener of that type. * * @param type - The event type to listen for. * @param listener - The listener to register. */ addEventListener(type: "close", listener: (event: { readonly code: number; }) => void): void; addEventListener(type: "error", listener: (event: unknown) => void): void; addEventListener(type: "message", listener: (event: { readonly data: unknown; }) => void): void; addEventListener(type: "open", listener: () => void): void; /** * Close the socket. Records the close code and flips `readyState` to CLOSED. Safe to repeat in the sense the seam needs: a second close simply records a second code. * * @param code - The close code. Defaults to 1000 (normal closure), matching the platform default. */ close(code?: number): void; /** * The current readyState: {@link WEBSOCKET_OPEN} until the first close, `WEBSOCKET_CLOSED` after. */ get readyState(): number; /** * Record an outbound frame. The frame is captured regardless of `readyState` so a test can assert the full wire sequence, including any send attempted after close. * * @param data - The frame text. */ send(data: string): void; /** * Dispatch a `close` event to every registered close listener and flip `readyState` to CLOSED, simulating the peer closing the connection. * * @param code - The close code to deliver. Defaults to 1000. */ emitClose(code?: number): void; /** * Dispatch an `error` event to every registered error listener, simulating a transport-level error. * * @param event - The error event payload. Defaults to an object carrying an `error` field, the shape the socket's error describer reads. */ emitError(event?: unknown): void; /** * Dispatch a `message` event carrying `data` to every registered message listener, simulating an inbound frame. * * @param data - The frame text (or any value, to exercise the socket's non-string guard). */ emitMessage(data: unknown): void; /** * Dispatch an `open` event to every registered open listener, simulating the transport-layer connection opening. */ emitOpen(): void; } /** * A {@link WebSocketFactory} double that records every `create` call (the connect URL) and returns a {@link TestWebSocket}. By default it returns a fresh socket per * call, which is exactly what the reconnect path needs - each connect attempt gets a distinct controllable socket - and the recorded sockets are retained in order so a * test can drive the second attempt's socket after failing the first. * * @category Testing */ export declare class TestWebSocketFactory { #private; readonly sockets: TestWebSocket[]; readonly urls: string[]; /** * Construct a WebSocket-factory double. * * @param socket - Optional fixed {@link TestWebSocket} to return from every `create`. When omitted, each `create` returns a fresh socket built with the call's URL. */ constructor(socket?: TestWebSocket); /** * The {@link WebSocketFactory} function this double exposes. Bound as an arrow property so it can be passed directly as the `webSocketFactory` seam without losing * `this`. * * @param url - The connect URL. * * @returns The recorded {@link TestWebSocket}. */ readonly create: WebSocketFactory; /** * Resolve when the socket at `index` (0-based, in creation order) has been constructed, returning it - immediately when it already exists. Lets a reconnect test * await the next connect attempt's socket deterministically instead of racing the reconnect loop's backoff against a fixed wall-clock delay. * * @param index - The 0-based creation-order index to await. * @returns A promise resolving to the {@link TestWebSocket} at that index. */ socketCreated(index: number): Promise; } /** * Construction-time configuration for a {@link TestLogSocket}. Every field defaults, so a bare `new TestLogSocket()` is usable. * * @property droppedLines - The value the `droppedLines` getter reports. Defaults to `0`. * @property lines - The raw log lines `stdout()` yields, in order, before it parks awaiting abort. Defaults to an empty array. * * @category Testing */ export interface TestLogSocketInit { droppedLines?: number; lines?: readonly string[]; } /** * A {@link LogSocketLike} test double. It yields caller-supplied lines from `stdout()` and then parks until aborted, mirroring how the real socket keeps a live stream * open after the seed; `abort()` aborts a genuine {@link AbortSignal} with a real {@link HbpuAbortError} reason so a consumer's abort-reason derivations stay meaningful. * A consumer can drive a client end to end against this double without a WebSocket. * * @category Testing */ export declare class TestLogSocket implements LogSocketLike { #private; readonly abortCalls: unknown[]; /** * Construct a log-socket double. * * @param init - Optional configuration. See {@link TestLogSocketInit}. Every field defaults, so a bare `new TestLogSocket()` is valid. */ constructor(init?: TestLogSocketInit); /** * Abort the socket. Aborts the internal signal with the supplied reason, defaulting to a real `HbpuAbortError("shutdown")`, and records the (defaulted) reason. Safe to * call more than once: the underlying signal aborts only once. * * @param reason - Optional abort reason. Typically an {@link HbpuAbortError}. */ abort(reason?: unknown): void; /** * `AsyncDisposable` implementation. Aborts the socket (defaulting to `"shutdown"`). * * @returns A resolved promise once the abort has been issued. */ [Symbol.asyncDispose](): Promise; /** * `true` once the socket's signal has aborted. */ get aborted(): boolean; /** * The configured dropped-line count. */ get droppedLines(): number; /** * The composed abort signal representing this socket's lifetime. Aborts exactly once, when `abort()` is called. */ get signal(): AbortSignal; /** * Yield the configured lines in order, then park until the socket aborts (mirroring a live stream that stays open after its seed). Terminates (returns) when the * signal aborts, so a consumer iterating this generator unwinds cleanly on `abort()` or disposal. * * @returns An async generator yielding the configured raw log lines, then parking until abort. */ stdout(): AsyncGenerator; } /** * A {@link LogSocketFactory} double that records every `create` call (the init it was passed) and returns a {@link TestLogSocket}, mirroring the create-call-recording * discipline `TestRecordingProcessFactory` uses. By default it returns a fresh, default-configured socket per call; supply a socket to the constructor to return a single * pre-configured instance from every `create`. * * @category Testing */ export declare class TestLogSocketFactory implements LogSocketFactory { #private; readonly createCalls: { init: LogSocketInit; socket: TestLogSocket; }[]; /** * Construct a log-socket-factory double. * * @param socket - Optional pre-configured {@link TestLogSocket} to return from every `create`. When omitted, each `create` returns a fresh, default-configured socket. */ constructor(socket?: TestLogSocket); /** * Record the create call and return a {@link TestLogSocket} - the constructor-supplied instance when one was given, otherwise a fresh default-configured one. * * @param init - The {@link LogSocketInit} the consumer passed. * * @returns The log-socket double. */ create(init: LogSocketInit): LogSocketLike; } //# sourceMappingURL=socket-double.d.ts.map