74 lines
2.1 KiB
TypeScript
74 lines
2.1 KiB
TypeScript
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { describe, expect, test } from "vitest";
|
|
|
|
const root = process.cwd();
|
|
const uiSourceRoot = existsSync(join(root, "packages/ui/src"))
|
|
? join(root, "packages/ui/src")
|
|
: join(root, "src");
|
|
|
|
const forbiddenTerms = [
|
|
"dimensionlab",
|
|
"dimension lab",
|
|
"vaultwarden",
|
|
"forgejo",
|
|
"grafana",
|
|
"uptime kuma",
|
|
"prometheus",
|
|
"backrest",
|
|
"open webui",
|
|
"comfyui",
|
|
"adminer",
|
|
"cockpit",
|
|
"ollama",
|
|
];
|
|
|
|
describe("UI package content boundary", () => {
|
|
test("contains the reusable dashboard component inventory", () => {
|
|
expect(existsSync(join(uiSourceRoot, "index.ts"))).toBe(true);
|
|
expect(existsSync(join(uiSourceRoot, "components/DashboardFrame.tsx"))).toBe(
|
|
true,
|
|
);
|
|
expect(existsSync(join(uiSourceRoot, "components/ThemeToggle.tsx"))).toBe(
|
|
true,
|
|
);
|
|
expect(existsSync(join(uiSourceRoot, "styles.css"))).toBe(true);
|
|
});
|
|
|
|
test("keeps environment-specific content out of reusable UI source", () => {
|
|
const source = readUiSource(uiSourceRoot).toLowerCase();
|
|
|
|
expect(forbiddenTerms.filter((term) => source.includes(term))).toEqual([]);
|
|
});
|
|
|
|
test("does not import website runtime modules", () => {
|
|
const source = readUiSource(uiSourceRoot);
|
|
|
|
expect(source).not.toMatch(
|
|
/from ["'](?:apps\/web|\$lib\/server|\$lib\/model)/,
|
|
);
|
|
expect(source).not.toContain("../web/");
|
|
});
|
|
|
|
test("keeps icon rendering driven by icon identifiers", () => {
|
|
const source = readUiSource(uiSourceRoot);
|
|
|
|
expect(source).not.toContain("@iconify-json/");
|
|
expect(source).not.toContain("/icons/");
|
|
});
|
|
});
|
|
|
|
function readUiSource(path: string): string {
|
|
if (!existsSync(path)) return "";
|
|
|
|
const stats = statSync(path);
|
|
if (stats.isFile()) {
|
|
if (path.endsWith(".test.ts") || path.endsWith(".test.tsx")) return "";
|
|
if (!/\.(tsx|ts|css)$/.test(path)) return "";
|
|
return readFileSync(path, "utf8");
|
|
}
|
|
|
|
return readdirSync(path)
|
|
.map((entry) => readUiSource(join(path, entry)))
|
|
.join("\n");
|
|
}
|