75 lines
2.4 KiB
TypeScript
75 lines
2.4 KiB
TypeScript
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
import { dirname, join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { describe, expect, it } from "@suaveplan/testing/runner";
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
const pkgRoot = join(here, "..");
|
|
const srcRoot = join(pkgRoot, "src");
|
|
const pkgJson = JSON.parse(
|
|
readFileSync(join(pkgRoot, "package.json"), "utf8")
|
|
) as { exports: Record<string, unknown> };
|
|
|
|
function walk(dir: string, out: string[] = []): string[] {
|
|
if (!existsSync(dir)) return out;
|
|
for (const entry of readdirSync(dir)) {
|
|
const p = join(dir, entry);
|
|
if (statSync(p).isDirectory()) walk(p, out);
|
|
else if (p.endsWith(".test.ts")) out.push(p);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
describe("exports", () => {
|
|
it("every feature module has a subpath export entry", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
const required = [
|
|
".",
|
|
"./codec/ffmpeg-wasm-codec",
|
|
"./worker/worker-host",
|
|
"./core-loader/core-loader",
|
|
"./decode/decode-pipeline",
|
|
"./encode/encode-pipeline",
|
|
"./streaming/streaming-decoder",
|
|
"./streaming/streaming-encoder",
|
|
"./register/register",
|
|
"./error-codes",
|
|
];
|
|
for (const sub of required) {
|
|
expect(pkgJson.exports[sub]).toBeDefined();
|
|
}
|
|
});
|
|
|
|
it("no test file imports vitest or bun:test directly", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
const tests = [...walk(srcRoot), ...walk(join(pkgRoot, "tests"))];
|
|
const offenders: string[] = [];
|
|
for (const f of tests) {
|
|
const text = readFileSync(f, "utf8");
|
|
if (/from\s+["'](vitest|bun:test)["']/.test(text)) {
|
|
offenders.push(f);
|
|
}
|
|
}
|
|
expect(offenders).toEqual([]);
|
|
});
|
|
|
|
it("package.json declares browser: true and sideEffects: false", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
const raw = JSON.parse(
|
|
readFileSync(join(pkgRoot, "package.json"), "utf8")
|
|
) as { browser?: boolean; sideEffects?: boolean };
|
|
expect(raw.browser).toBe(true);
|
|
expect(raw.sideEffects).toBe(false);
|
|
});
|
|
|
|
it("each feature module is independently importable", {
|
|
timeout: 5000,
|
|
}, async () => {
|
|
const mod = await import("../src/register/register.js");
|
|
expect(typeof mod.register).toBe("function");
|
|
});
|
|
});
|