Testing
Overview
Section titled “Overview”@serviceconnect/core/testing is a subpath of the core package containing test
helpers: an in-memory transport double so you can exercise a bus without a live
broker, and shared contract suites that a new persistence backend runs against
its store implementations to prove conformance. None of these helpers are
included in the main @serviceconnect/core entry point — import them from the
/testing subpath so they stay out of production bundles.
Import
Section titled “Import”import { fakeTransport, runSagaStoreContract } from '@serviceconnect/core/testing';import type { FakeTransport, FakeTransportOptions, OutboxEntry,} from '@serviceconnect/core/testing';Transport doubles
Section titled “Transport doubles”export function fakeTransport(opts?: FakeTransportOptions): FakeTransport;export function fakeProducer(opts?: FakeTransportOptions): ITransportProducer;export function fakeConsumer(opts?: FakeTransportOptions): ITransportConsumer;fakeTransport(opts?)— build an in-memory transport double for bus tests with no broker required. Returns{ producer, consumer }plus anoutboxarray ofOutboxEntrycapturing everything that was published or sent. The returned object also exposesdeliver(envelope)to feed an inbound message to the consumer, andcancelByBroker()/disconnect()/reconnect()to simulate connection state for health-check tests.fakeProducer(opts?)— convenience accessor returning just theproducerfrom a freshfakeTransport.fakeConsumer(opts?)— convenience accessor returning just theconsumerfrom a freshfakeTransport.
FakeTransportOptions lets you toggle transport capabilities the bus probes:
export interface FakeTransportOptions { readonly supportsRoutingKey?: boolean; // default false readonly maxMessageSize?: number; // default Number.POSITIVE_INFINITY}OutboxEntry
Section titled “OutboxEntry”Each outbound operation appends one entry to transport.outbox:
export interface OutboxEntry { readonly operation: 'publish' | 'send' | 'sendBytes'; readonly typeName: string; readonly endpoint?: string; readonly body: Uint8Array; readonly headers: Readonly<Record<string, string>>; readonly routingKey?: string; readonly routingSlipHopsCompleted?: number;}Assert against transport.outbox to verify what your handlers published or sent
without round-tripping through a real broker.
Store contract suites
Section titled “Store contract suites”export function runSagaStoreContract(...): void;export function runAggregatorStoreContract(...): void;export function runTimeoutStoreContract(...): void;Shared Vitest suites that a new persistence backend runs against its store implementations to prove conformance:
runSagaStoreContract— the conformance suite for anISagaStoreimplementation (optimistic concurrency, load/save/delete semantics).runAggregatorStoreContract— the conformance suite for anIAggregatorStoreimplementation (buffering, lease-based flush, timeout expiry).runTimeoutStoreContract— the conformance suite for anITimeoutStoreimplementation (scheduling and due-timeout dispatch).
Call the relevant suite from your backend’s test file, handing it a factory for your store, and it asserts the same behaviour the in-tree memory and MongoDB backends are held to.