testing/transports/sse_transport.ts

Cross-process Server-Sent Events transport.

Opens a real streaming fetch against a spawned test binary's SSE endpoint, threading the session cookie captured by the sibling FetchTransport so the stream authenticates as the same account, then delegates frame parsing to the shared create_sse_frame_reader. Uses only built-in streaming fetch + TextDecoder — no extra dep.

Mirrors how testing/transports/ws_transport.ts is the cross-process counterpart to the in-process WS harness; the in-process SSE route suite (testing/sse_round_trip.ts) shares the same create_sse_frame_reader over a Hono Response.body.

view source

Declarations
#

3 declarations

create_sse_transport
#

testing/transports/sse_transport.ts view source

(options: SseTransportOptions): Promise<SseTransport> import {create_sse_transport} from '@fuzdev/fuz_app/testing/transports/sse_transport.js';

Open a real-HTTP SSE stream pinned to options.base_url + sse_path.

Resolves once the response headers arrive and the body is a text/event-stream; rejects if the connect is refused (non-2xx status, wrong content type, missing body) so the test surfaces the real cause rather than hanging.

options

returns

Promise<SseTransport>

throws

  • Error - if the connect fails (status, content type, or no body).

SseTransport
#

testing/transports/sse_transport.ts view source

SseTransport import type {SseTransport} from '@fuzdev/fuz_app/testing/transports/sse_transport.js';

A cross-process SSE client: read frames, await server close, cancel.

read_frame

Read one complete SSE frame (up to the next \n\n), without the trailing terminator. Throws if the per-read timeout elapses or the stream ends before a frame arrives.

type (timeout_ms?: number) => Promise<string>

wait_for_close

Drain until the server closes the stream. Resolves true if the stream closes within timeout_ms, false on timeout. The signal for an auth-guard revocation dropping a live stream — mirrors WsClient.wait_for_close.

type (timeout_ms?: number) => Promise<boolean>

close

Cancel the reader (client-initiated close). Safe to call when already closed.

type () => Promise<void>

SseTransportOptions
#

testing/transports/sse_transport.ts view source

SseTransportOptions import type {SseTransportOptions} from '@fuzdev/fuz_app/testing/transports/sse_transport.js';

Construction options for create_sse_transport.

base_url

Base URL the binary is reachable at — e.g. http://localhost:1178.

type string

readonly

sse_path

SSE endpoint path on the binary (e.g. /api/admin/audit/stream).

type string

readonly

cookies

Session cookie values (full Set-Cookie strings as FetchTransport.cookies() returns them) threaded onto the request Cookie header. Without these the stream is anonymous and the connect is refused (the audit stream requires an admin session).

type ReadonlyArray<string>

readonly

origin?

Origin header for the request. 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?

Default per-read / wait-for-close timeout. Falls back to 2000ms.

type number

readonly

Depends on
#

Imported by
#