Files
HiveGrid-Wireframes/hivegrid-cloud/apps/web/app/utils/build/bundleScan.test.ts
T

84 lines
2.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { analyzeBundleScan, formatBundleScanSummary } from "./bundleScan";
describe("bundle scan", () => {
it("reports actionable over-budget vendor chunks", () => {
const result = analyzeBundleScan({
assets: [{ name: "assets/vendor-react.abcd.js", sizeKb: 620 }],
warnings: [
{
code: "PLUGIN_WARNING",
message: "Some chunks are larger than 500 kB after minification.",
},
],
});
expect(result.budgetViolations).toEqual([
{
name: "assets/vendor-react.abcd.js",
sizeKb: 620,
thresholdKb: 500,
budgetKind: "vendor",
},
]);
expect(result.warnings[0]?.class).toBe("large-chunk");
});
it("accepts chunks within explicit app, vendor and editor budgets", () => {
const result = analyzeBundleScan({
assets: [
{ name: "assets/routes-dashboard.js", sizeKb: 340 },
{ name: "assets/vendor-radix.js", sizeKb: 480 },
{ name: "assets/monaco-editor.js", sizeKb: 840 },
],
});
expect(result.budgetViolations).toEqual([]);
});
it("formats largest chunk summaries in deterministic size order", () => {
const result = analyzeBundleScan(
{
assets: [
{ name: "assets/workflow.js", sizeKb: 220 },
{ name: "assets/vendor-react.js", sizeKb: 500 },
{ name: "assets/editor-monaco.js", sizeKb: 500 },
{ name: "assets/settings.js", sizeKb: 120 },
],
},
{ largestChunkLimit: 3 },
);
expect(result.largestChunks.map((asset) => asset.name)).toEqual([
"assets/editor-monaco.js",
"assets/vendor-react.js",
"assets/workflow.js",
]);
expect(formatBundleScanSummary(result)).toContain("- assets/editor-monaco.js: 500 kB");
});
it("keeps unknown warnings visible instead of suppressing them", () => {
const result = analyzeBundleScan({
assets: [{ name: "assets/app.js", sizeKb: 100 }],
warnings: [
{
code: "SYNTHETIC_NEW_WARNING",
message: "Bundler emitted a warning this helper does not know yet.",
file: "apps/web/app/routes/dashboard.tsx",
},
],
});
expect(result.unknownWarnings).toHaveLength(1);
expect(result.unknownWarnings[0]).toMatchObject({
class: "unknown",
suppressed: false,
code: "SYNTHETIC_NEW_WARNING",
});
expect(formatBundleScanSummary(result)).toContain(
"- SYNTHETIC_NEW_WARNING: Bundler emitted a warning this helper does not know yet.",
);
});
});