// mirrors chunk A — see ../../src/transports/transport.types.ts header for spec link. import { readdir, readFile, stat } from "node:fs/promises"; import { dirname, join, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import { describe, expect, it } from "@suaveplan/testing/runner"; const HERE = dirname(fileURLToPath(import.meta.url)); const TRANSPORTS = resolve(HERE, "..", "..", "src", "transports"); async function walk(dir: string): Promise { const out: string[] = []; const entries = await readdir(dir); for (const entry of entries) { const full = join(dir, entry); const st = await stat(full); if (st.isDirectory()) { out.push(...(await walk(full))); } else if (full.endsWith(".ts") && !full.endsWith(".test.ts")) { out.push(full); } } return out; } describe("webrtc transport bundle purity", () => { it("only the trystero adapter source references trystero", { timeout: 5000, }, async () => { const files = await walk(TRANSPORTS); expect(files.length).toBeGreaterThan(0); const offenders: string[] = []; for (const file of files) { const text = await readFile(file, "utf8"); if (!text.includes("network-discovery-trystero")) continue; if (file.includes(`${"trystero".toString()}/`)) continue; offenders.push(file); } expect(offenders).toEqual([]); }); it("webrtc and websocket adapters do not import trystero", { timeout: 5000, }, async () => { const targets = [ join(TRANSPORTS, "webrtc", "webrtc-transport.ts"), join(TRANSPORTS, "webrtc", "webrtc-transport.types.ts"), join(TRANSPORTS, "webrtc", "index.ts"), join(TRANSPORTS, "websocket", "websocket-transport.ts"), join(TRANSPORTS, "websocket", "websocket-transport.types.ts"), join(TRANSPORTS, "websocket", "index.ts"), join(TRANSPORTS, "transport.types.ts"), ]; for (const file of targets) { const text = await readFile(file, "utf8"); expect(text.includes("network-discovery-trystero")).toBe(false); expect(text.includes('from "trystero"')).toBe(false); } }); it("trystero adapter uses a lazy loader, never a static import", { timeout: 5000, }, async () => { const text = await readFile( join(TRANSPORTS, "trystero", "trystero-transport.ts"), "utf8" ); const staticImport = /^\s*import\s+[^;]*from\s+["']@suaveplan\/network-discovery-trystero["']/m; expect(staticImport.test(text)).toBe(false); expect(text.includes("config.loader")).toBe(true); }); });