Files
suaveplan/packages/devtools/tooling/linter/tests/package-shape.test.ts
2026-05-27 23:29:53 +01:00

44 lines
1.4 KiB
TypeScript

import { readdirSync, readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "@suaveplan/testing/runner";
const PKG_ROOT = join(__dirname, "..");
const packageJson = JSON.parse(
readFileSync(join(PKG_ROOT, "package.json"), "utf-8")
) as {
sideEffects: unknown;
bin: Record<string, string>;
exports: Record<string, unknown>;
};
describe("package shape", () => {
it("every feature folder has a matching subpath export", {
timeout: 5000,
}, () => {
const srcDir = join(PKG_ROOT, "src");
const featureFolders = readdirSync(srcDir, {
withFileTypes: true,
})
.filter(
(e) => e.isDirectory() && e.name !== "types" // shared types — no subpath
)
.map((e) => e.name)
.sort();
const subpathKeys = Object.keys(packageJson.exports)
.filter((k) => k.startsWith("./") && k !== "./package.json")
.map((k) => k.replace(/^\.\//, ""))
.filter((k) => k !== "" && !k.includes("."));
for (const folder of featureFolders) {
expect(subpathKeys).toContain(folder);
}
});
it("sideEffects is false", { timeout: 5000 }, () => {
expect(packageJson.sideEffects).toBe(false);
});
it("bin entry is registered", { timeout: 5000 }, () => {
expect(packageJson.bin["suaveplan-lint"]).toBe("./dist/bin.js");
});
});