Files
NianAIGC/tests/frontend-environment-copy.test.ts

41 lines
1.2 KiB
TypeScript

import { readdir, readFile } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
const forbiddenCopy = [
"本地",
"开发环境",
"Mock",
".runtime/",
"演示用户"
];
describe("production-facing copy", () => {
it("does not expose development or implementation labels in React UI", async () => {
const files = [
...await sourceFiles(join(process.cwd(), "app")),
...await sourceFiles(join(process.cwd(), "components"))
];
const matches: string[] = [];
for (const file of files) {
const source = await readFile(file, "utf8");
for (const copy of forbiddenCopy) {
if (source.includes(copy)) matches.push(`${file}: ${copy}`);
}
}
expect(matches).toEqual([]);
});
});
async function sourceFiles(directory: string): Promise<string[]> {
const entries = await readdir(directory, { withFileTypes: true });
const files = await Promise.all(entries.map(async (entry) => {
const path = join(directory, entry.name);
if (entry.isDirectory()) return sourceFiles(path);
return entry.isFile() && path.endsWith(".tsx") ? [path] : [];
}));
return files.flat();
}