Initial Commit
This commit is contained in:
66
packages/testkit/testing/testing-e2e/tests/dep-graph.test.ts
Normal file
66
packages/testkit/testing/testing-e2e/tests/dep-graph.test.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
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", {
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
it("cloakbrowser is a direct dependency", { timeout: 5000 }, async () => {
|
||||
const pkg = JSON.parse(await readFile(pkgPath, "utf8")) as {
|
||||
dependencies?: Record<string, string>;
|
||||
};
|
||||
expect(pkg.dependencies?.cloakbrowser).toBeDefined();
|
||||
// Either a catalog reference or an absolute range is acceptable.
|
||||
expect(pkg.dependencies?.cloakbrowser).toMatch(
|
||||
/^(catalog:testing|\^?\d|~?\d|\d)/
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user