-
Notifications
You must be signed in to change notification settings - Fork 676
Expand file tree
/
Copy pathcheck-file-sizes.test.mjs
More file actions
56 lines (47 loc) · 1.74 KB
/
Copy pathcheck-file-sizes.test.mjs
File metadata and controls
56 lines (47 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { mkdir, mkdtemp, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { checkFileSizes, formatFileSizeReport } from "./check-file-sizes.mjs";
const createFixtureRepo = async () => {
const repoRoot = await mkdtemp(join(tmpdir(), "chartkit-file-size-"));
await mkdir(join(repoRoot, "packages/core/src"), { recursive: true });
await mkdir(join(repoRoot, "packages/core/dist"), { recursive: true });
return repoRoot;
};
describe("file size checker", () => {
it("reports files above the configured line budget", async () => {
const repoRoot = await createFixtureRepo();
await writeFile(
join(repoRoot, "packages/core/src/large.ts"),
Array.from({ length: 6 }, (_, index) => `line${index}`).join("\n"),
"utf8"
);
await writeFile(
join(repoRoot, "packages/core/src/small.ts"),
"line1\nline2\n",
"utf8"
);
await writeFile(
join(repoRoot, "packages/core/dist/generated.ts"),
Array.from({ length: 20 }, (_, index) => `line${index}`).join("\n"),
"utf8"
);
const result = await checkFileSizes({ maxLines: 5, repoRoot });
expect(result).toMatchObject({
checked: 2,
maxLines: 5,
oversized: [{ lines: 6, path: "packages/core/src/large.ts" }]
});
expect(formatFileSizeReport(result)).toContain(
"packages/core/src/large.ts: 6 lines"
);
});
it("prints a pass message when all scanned files are within budget", async () => {
const result = await checkFileSizes({
repoRoot: process.cwd()
});
expect(result.oversized).toEqual([]);
expect(formatFileSizeReport(result)).toContain("File size check passed");
});
});