Files
2026-05-27 23:47:53 +01:00

68 lines
2.3 KiB
TypeScript

import * as fs from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "@suaveplan/testing/runner";
const PKG_ROOT = join(import.meta.dirname ?? __dirname, "..");
const DIST = join(PKG_ROOT, "dist");
function walk(dir: string, out: string[] = []): string[] {
for (const name of fs.readdirSync(dir)) {
const p = join(dir, name);
const st = fs.statSync(p);
if (st.isDirectory()) walk(p, out);
else if (p.endsWith(".js")) out.push(p);
}
return out;
}
describe("purity", () => {
it("dist references no Node globals", { timeout: 5000 }, () => {
const files = walk(DIST);
expect(files.length).toBeGreaterThan(0);
const banned = [/\bnode:fs\b/, /\bnode:path\b/, /\bnode:crypto\b/];
const hits: string[] = [];
for (const file of files) {
const content = fs.readFileSync(file, "utf8");
for (const rx of banned) {
if (rx.test(content)) hits.push(`${file}:${rx}`);
}
}
expect(hits).toEqual([]);
});
it("dependency set is limited to the declared workspace, standardized-audio-context, and zod", {
timeout: 5000,
}, () => {
const pkg = JSON.parse(
fs.readFileSync(join(PKG_ROOT, "package.json"), "utf8")
) as { dependencies: Record<string, string> };
const allowed = new Set([
"@suaveplan/audio-core",
"@suaveplan/audio-fx-plugin-base",
"@suaveplan/audio-timeline",
"@suaveplan/audio-transport",
"@suaveplan/error",
"@suaveplan/events",
"@opentelemetry/api",
"standardized-audio-context",
"tslib",
"zod",
]);
for (const dep of Object.keys(pkg.dependencies)) {
expect(allowed).toContain(dep);
}
});
it("importing the package mutates no global state", {
timeout: 5000,
}, async () => {
const before = new Set(Object.keys(globalThis));
await import("../src/index.js");
const after = new Set(Object.keys(globalThis));
for (const k of after) {
if (before.has(k)) continue;
expect(k).not.toMatch(/audio.engine.browser/i);
}
});
});