Initial Commit
This commit is contained in:
43
packages/devtools/tooling/linter/tests/package-shape.test.ts
Normal file
43
packages/devtools/tooling/linter/tests/package-shape.test.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
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");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user