import { readdirSync, readFileSync, statSync } from "node:fs"; import { join } from "node:path"; import { describe, expect, it } from "@suaveplan/testing/runner"; const ROOT = join(__dirname, "..", "src"); function walkTs(dir: string): string[] { const out: string[] = []; for (const name of readdirSync(dir)) { const full = join(dir, name); if (statSync(full).isDirectory()) out.push(...walkTs(full)); else if ( full.endsWith(".ts") && !full.endsWith(".test.ts") && !full.endsWith(".bench.ts") ) { out.push(full); } } return out; } describe("purity", () => { it("source tree references no browser globals", { timeout: 5000 }, () => { const banned = ["AudioContext", "AudioBuffer", "AudioWorklet"]; for (const file of walkTs(ROOT)) { const text = readFileSync(file, "utf-8"); for (const term of banned) { expect(text.includes(term)).toBe(false); } } }); it("dependency set is limited to the declared workspace deps and zod", { timeout: 5000, }, () => { const pkg = JSON.parse( readFileSync(join(__dirname, "..", "package.json"), "utf-8") ); const deps = Object.keys(pkg.dependencies ?? {}).sort(); const allowed = [ "@opentelemetry/api", "@suaveplan/audio-codecs", "@suaveplan/audio-core", "@suaveplan/audio-timeline", "@suaveplan/audio-transport", "@suaveplan/error", "@suaveplan/opentelemetry", "@suaveplan/streams", "@suaveplan/types", "tslib", "zod", ].sort(); expect(deps).toEqual(allowed); }); it("importing the package mutates no global state", { timeout: 5000, }, async () => { // Importing twice should not mutate globalThis between calls. await import("../src/index.js"); const before = Object.keys(globalThis).length; await import("../src/index.js"); const after = Object.keys(globalThis).length; expect(after).toBe(before); }); });