/** * Dependency graph smoke test — verifies the package entry point exports * all expected symbols and that no unexpected runtime imports are present. */ import { describe, expect, it } from "@suaveplan/testing/runner"; import * as Transport from "../src/index.js"; describe("@suaveplan/events-transport — public API surface", () => { it("exports createMessageChannelTransport", { timeout: 5000 }, () => { expect(typeof Transport.createMessageChannelTransport).toBe("function"); }); it("exports createBroadcastChannelTransport", { timeout: 5000 }, () => { expect(typeof Transport.createBroadcastChannelTransport).toBe( "function" ); }); it("exports buildEnvelope and parseEnvelope", { timeout: 5000 }, () => { expect(typeof Transport.buildEnvelope).toBe("function"); expect(typeof Transport.parseEnvelope).toBe("function"); }); it("exports NonceWindow", { timeout: 5000 }, () => { expect(typeof Transport.NonceWindow).toBe("function"); }); it("exports isStructuredCloneable and assertStructuredCloneable", { timeout: 5000, }, () => { expect(typeof Transport.isStructuredCloneable).toBe("function"); expect(typeof Transport.assertStructuredCloneable).toBe("function"); }); it("exports EventsTransportError", { timeout: 5000 }, () => { expect(typeof Transport.EventsTransportError).toBe("function"); }); it("exports EVENTS_TRANSPORT_CODES", { timeout: 5000 }, () => { expect(typeof Transport.EVENTS_TRANSPORT_CODES).toBe("object"); }); it("registerEventsTransportErrorCodes is a no-op function", { timeout: 5000, }, () => { expect(() => Transport.registerEventsTransportErrorCodes() ).not.toThrow(); }); it("exports constants", { timeout: 5000 }, () => { expect(typeof Transport.DEFAULT_ACK_TIMEOUT_MS).toBe("number"); expect(typeof Transport.DEFAULT_MAX_RETRIES).toBe("number"); expect(typeof Transport.DEFAULT_NONCE_WINDOW_SIZE).toBe("number"); expect(typeof Transport.ENVELOPE_VERSION).toBe("number"); }); it("createMessageChannelTransport returns correct transport shape", { timeout: 5000, }, () => { const channel = new MessageChannel(); const transport = Transport.createMessageChannelTransport({ channel }); expect(transport.name).toBe("message-channel"); expect(transport.deliveryGuarantee).toBe("at-least-once"); expect(typeof transport.connect).toBe("function"); channel.port1.close(); channel.port2.close(); }); it("createBroadcastChannelTransport with mock channel shape", { timeout: 5000, }, () => { // Minimal mock since BroadcastChannel is not available in Node test env const mockChannel = { name: "test", addEventListener: () => {}, removeEventListener: () => {}, postMessage: () => {}, close: () => {}, } as unknown as BroadcastChannel; const transport = Transport.createBroadcastChannelTransport({ channel: mockChannel, }); expect(transport.name).toBe("broadcast-channel"); expect(transport.deliveryGuarantee).toBe("at-most-once"); }); it("NonceWindow tracks and deduplicates nonces", { timeout: 5000 }, () => { const nw = new Transport.NonceWindow(10); expect(nw.check("a")).toBe(false); // new expect(nw.check("a")).toBe(true); // duplicate expect(nw.check("b")).toBe(false); // new }); it("buildEnvelope and parseEnvelope round-trips correctly", { timeout: 5000, }, () => { const env = Transport.buildEnvelope( "test.event", { id: "1" }, { nonce: "n1", origin: "local", ts: 1000, } ); const parsed = Transport.parseEnvelope(env); expect(parsed.event).toBe("test.event"); expect(parsed.payload).toEqual({ id: "1" }); expect(parsed.nonce).toBe("n1"); }); it("isStructuredCloneable returns correct results", { timeout: 5000, }, () => { expect(Transport.isStructuredCloneable({ a: 1 })).toBe(true); expect(Transport.isStructuredCloneable(() => {})).toBe(false); }); });