Initial Commit
This commit is contained in:
60
packages/testkit/testing/testing-dom/tests/dep-graph.test.ts
Normal file
60
packages/testkit/testing/testing-dom/tests/dep-graph.test.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Dep-graph guard — runtime closure of @suaveplan/testing-dom must
|
||||
* contain zero `@suaveplan/*` packages. devDeps may include
|
||||
* @suaveplan/testing for our own tests.
|
||||
*/
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { describe, expect, it } from "../src/runner/index.js";
|
||||
|
||||
const here = dirname(fileURLToPath(import.meta.url));
|
||||
const pkgPath = resolve(here, "..", "package.json");
|
||||
|
||||
describe("dep-graph guard", () => {
|
||||
it("no @suaveplan/* in dependencies or peerDependencies", {
|
||||
timeout: 5000,
|
||||
}, async () => {
|
||||
const pkg = JSON.parse(await readFile(pkgPath, "utf8")) as {
|
||||
dependencies?: Record<string, string>;
|
||||
peerDependencies?: Record<string, string>;
|
||||
};
|
||||
const sections: Array<
|
||||
[
|
||||
"dependencies" | "peerDependencies",
|
||||
Record<string, string> | undefined,
|
||||
]
|
||||
> = [
|
||||
["dependencies", pkg.dependencies],
|
||||
["peerDependencies", pkg.peerDependencies],
|
||||
];
|
||||
for (const [name, deps] of sections) {
|
||||
if (!deps) continue;
|
||||
const offending = Object.keys(deps).filter((k) =>
|
||||
k.startsWith("@suaveplan/")
|
||||
);
|
||||
expect(
|
||||
offending,
|
||||
`${name} contains @suaveplan/* deps: ${offending.join(", ")}`
|
||||
).toEqual([]);
|
||||
}
|
||||
});
|
||||
|
||||
it("devDependencies may contain @suaveplan/testing only (utilities for our own tests)", {
|
||||
timeout: 5000,
|
||||
}, async () => {
|
||||
const pkg = JSON.parse(await readFile(pkgPath, "utf8")) as {
|
||||
devDependencies?: Record<string, string>;
|
||||
};
|
||||
const ours = Object.keys(pkg.devDependencies ?? {}).filter((k) =>
|
||||
k.startsWith("@suaveplan/")
|
||||
);
|
||||
const allowed = new Set(["@suaveplan/testing"]);
|
||||
for (const dep of ours) {
|
||||
expect(
|
||||
allowed.has(dep),
|
||||
`unexpected @suaveplan/* devDep: ${dep}`
|
||||
).toBe(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user