Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import path from "node:path";
|
||||
|
||||
import {
|
||||
BUDGETS,
|
||||
@@ -10,11 +11,16 @@ import {
|
||||
findUnexpectedEmptyJsChunks,
|
||||
formatDriftPercent,
|
||||
getLargestJsChunks,
|
||||
isJavaScriptAsset,
|
||||
isLazyRuntimeChunkName,
|
||||
isRouteChunkName,
|
||||
isVendorChunkName,
|
||||
loadBudgetsConfig,
|
||||
lookupBudget,
|
||||
measureInitialPayload,
|
||||
normalizeAssetBaselineName,
|
||||
parseReactRouterManifest,
|
||||
parseStaticImportSpecifiers,
|
||||
readAssetFiles,
|
||||
runBundleSizeGate,
|
||||
runCli,
|
||||
@@ -50,21 +56,34 @@ function makeDirent(name) {
|
||||
}
|
||||
|
||||
function stubAssets(files) {
|
||||
const resolvedFiles = [...files];
|
||||
let entry = resolvedFiles.find((file) => file.name.startsWith("entry.client-") && file.name.endsWith(".js"));
|
||||
if (!entry) {
|
||||
entry = { name: "entry.client-FIXTURE.js", size: 10, content: "export {};" };
|
||||
resolvedFiles.push(entry);
|
||||
}
|
||||
if (!resolvedFiles.some((file) => /^manifest-.+\.js$/.test(file.name))) {
|
||||
const content = `window.__reactRouterManifest=${JSON.stringify({
|
||||
entry: { module: `/assets/${entry.name}`, imports: [], css: [] },
|
||||
routes: { root: { id: "root", module: `/assets/${entry.name}`, imports: [] } },
|
||||
})};`;
|
||||
resolvedFiles.push({ name: "manifest-FIXTURE.js", size: Buffer.byteLength(content), content });
|
||||
}
|
||||
fsState.readFile.mockReset();
|
||||
fsState.readdir.mockReset();
|
||||
fsState.stat.mockReset();
|
||||
fsState.readdir.mockResolvedValue(files.map((file) => makeDirent(file.name)));
|
||||
fsState.readdir.mockResolvedValue(resolvedFiles.map((file) => makeDirent(file.name)));
|
||||
fsState.readFile.mockImplementation(async (full) => {
|
||||
const base = String(full).split("/").pop();
|
||||
const match = files.find((file) => file.name === base);
|
||||
const base = path.basename(String(full));
|
||||
const match = resolvedFiles.find((file) => file.name === base);
|
||||
if (!match) {
|
||||
throw Object.assign(new Error(`readFile: ${full} not stubbed`), { code: "ENOENT" });
|
||||
}
|
||||
return Buffer.alloc(match.contentSize ?? Math.max(1, match.size), "a");
|
||||
return match.content !== undefined ? Buffer.from(match.content) : Buffer.alloc(match.contentSize ?? Math.max(1, match.size), "a");
|
||||
});
|
||||
fsState.stat.mockImplementation(async (full) => {
|
||||
const base = String(full).split("/").pop();
|
||||
const match = files.find((file) => file.name === base);
|
||||
const base = path.basename(String(full));
|
||||
const match = resolvedFiles.find((file) => file.name === base);
|
||||
if (!match) {
|
||||
throw Object.assign(new Error(`stat: ${full} not stubbed`), { code: "ENOENT" });
|
||||
}
|
||||
@@ -90,7 +109,7 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
describe("classifyChunk", () => {
|
||||
it("classifies root, vendor, route, other and css", () => {
|
||||
it("classifies root, vendor, route, other, lazy runtime and css", () => {
|
||||
expect(classifyChunk("entry.client-AAAA.js")).toBe("root");
|
||||
expect(classifyChunk("root-BBBB.js")).toBe("root");
|
||||
expect(classifyChunk("manifest-9cc2.js")).toBe("root");
|
||||
@@ -99,6 +118,11 @@ describe("classifyChunk", () => {
|
||||
expect(classifyChunk("(_lang)-AAAA.js")).toBe("route");
|
||||
expect(classifyChunk("events._id-AAAA.js")).toBe("route");
|
||||
expect(classifyChunk("dashboard-AAAAAA.js")).toBe("route");
|
||||
expect(classifyChunk("MonacoEditor.client-AAAA.js")).toBe("lazy_runtime");
|
||||
expect(classifyChunk("lazy-monaco-jsonMode-AAAA.js")).toBe("lazy_runtime");
|
||||
expect(classifyChunk("lazy-pdfjs-pdf-AAAA.js")).toBe("lazy_runtime");
|
||||
expect(classifyChunk("ts.worker-AAAA.js")).toBe("lazy_runtime");
|
||||
expect(classifyChunk("pdf.worker.min-AAAA.mjs")).toBe("lazy_runtime");
|
||||
expect(classifyChunk("AppLayout-AAAA.js")).toBe("other");
|
||||
expect(classifyChunk("AppLayout-AAAA.css")).toBe("css");
|
||||
expect(classifyChunk("README.txt")).toBeNull();
|
||||
@@ -115,6 +139,7 @@ describe("evaluateBudgets", () => {
|
||||
{ name: "vendor-editor-EEEE.js", size: 500 },
|
||||
{ name: "(_lang)-FFFF.js", size: 700 },
|
||||
{ name: "AppLayout-GGGG.js", size: 1_000 },
|
||||
{ name: "ts.worker-HHHH.js", size: 600 },
|
||||
{ name: "AppLayout-HHHH.css", size: 250 },
|
||||
];
|
||||
const results = evaluateBudgets(files, BUDGETS);
|
||||
@@ -127,7 +152,9 @@ describe("evaluateBudgets", () => {
|
||||
expect(totals.vendor).toBe(900);
|
||||
expect(totals.route).toBe(700);
|
||||
expect(totals.other).toBe(1_000);
|
||||
expect(totals.total_js).toBe(3_200);
|
||||
expect(totals.lazy_runtime).toBe(600);
|
||||
expect(totals.application_js).toBe(3_200);
|
||||
expect(totals.total_js).toBe(3_800);
|
||||
expect(totals.css).toBe(250);
|
||||
});
|
||||
|
||||
@@ -150,7 +177,7 @@ describe("evaluateBudgets", () => {
|
||||
expect(results.find((r) => r.group === "vendor").pass).toBe(true);
|
||||
});
|
||||
|
||||
it("accumulates total_js across all four JS groups", () => {
|
||||
it("keeps the application signal separate while total_js includes lazy runtimes", () => {
|
||||
const files = [
|
||||
{ name: "entry.client-A.js", size: 11 },
|
||||
{ name: "root-A.js", size: 13 },
|
||||
@@ -160,11 +187,14 @@ describe("evaluateBudgets", () => {
|
||||
{ name: "(_lang)-A.js", size: 29 },
|
||||
{ name: "foo._id-A.js", size: 31 },
|
||||
{ name: "Component-A.js", size: 37 },
|
||||
{ name: "ts.worker-A.js", size: 41 },
|
||||
{ name: "Component-A.css", size: 999 }, // CSS must not bleed into total_js
|
||||
];
|
||||
const results = evaluateBudgets(files, BUDGETS);
|
||||
const applicationJs = results.find((r) => r.group === "application_js").total;
|
||||
const totalJs = results.find((r) => r.group === "total_js").total;
|
||||
expect(totalJs).toBe(11 + 13 + 17 + 19 + 23 + 29 + 31 + 37);
|
||||
expect(applicationJs).toBe(11 + 13 + 17 + 19 + 23 + 29 + 31 + 37);
|
||||
expect(totalJs).toBe(applicationJs + 41);
|
||||
expect(results.find((r) => r.group === "css").total).toBe(999);
|
||||
});
|
||||
|
||||
@@ -178,7 +208,7 @@ describe("evaluateBudgets", () => {
|
||||
{ name: "(_lang)-A.js", size: 23 },
|
||||
{ name: "Component-A.js", size: 29 },
|
||||
],
|
||||
BUDGETS,
|
||||
BUDGETS
|
||||
);
|
||||
|
||||
expect(results.find((r) => r.group === "initial_payload_js")).toMatchObject({
|
||||
@@ -224,6 +254,16 @@ describe("formatDriftPercent", () => {
|
||||
});
|
||||
|
||||
describe("build artifact helpers", () => {
|
||||
it("recognizes JavaScript and self-hosted lazy runtime assets", () => {
|
||||
expect(isJavaScriptAsset("runtime.js")).toBe(true);
|
||||
expect(isJavaScriptAsset("pdf.worker.min-AAAA.mjs")).toBe(true);
|
||||
expect(isJavaScriptAsset("runtime.js.gz")).toBe(false);
|
||||
expect(isLazyRuntimeChunkName("MonacoEditor.client-AAAA.js")).toBe(true);
|
||||
expect(isLazyRuntimeChunkName("lazy-monaco-tsMode-AAAA.js")).toBe(true);
|
||||
expect(isLazyRuntimeChunkName("pdf-AAAA.js")).toBe(true);
|
||||
expect(isLazyRuntimeChunkName("dashboard-AAAA.js")).toBe(false);
|
||||
});
|
||||
|
||||
it("normalizes hashed asset names to stable baseline names", () => {
|
||||
expect(normalizeAssetBaselineName("readyz-l0sNRNKZ.js")).toBe("readyz");
|
||||
expect(normalizeAssetBaselineName("entry.client-CLC9Ig9o.js")).toBe("entry.client");
|
||||
@@ -253,8 +293,8 @@ describe("build artifact helpers", () => {
|
||||
{ name: "empty.js", size: 0 },
|
||||
{ name: "style.css", size: 300 },
|
||||
],
|
||||
2,
|
||||
),
|
||||
2
|
||||
)
|
||||
).toEqual([
|
||||
{ name: "large-a.js", size: 200 },
|
||||
{ name: "large-b.js", size: 200 },
|
||||
@@ -266,6 +306,35 @@ describe("build artifact helpers", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("initial static import graph", () => {
|
||||
it("parses the React Router manifest assignment and excludes dynamic imports", () => {
|
||||
const source = 'window.__reactRouterManifest={"entry":{"module":"/assets/entry.js"},"routes":{"root":{"module":"/assets/root.js"}}};';
|
||||
expect(parseReactRouterManifest(source).entry.module).toBe("/assets/entry.js");
|
||||
expect(parseStaticImportSpecifiers('import{a}from"./a.js";import"./b.js";const lazy=import("./lazy.js");')).toEqual(["./a.js", "./b.js"]);
|
||||
});
|
||||
|
||||
it("recursively measures entry and root static imports in raw, gzip and brotli bytes", async () => {
|
||||
const manifest = `window.__reactRouterManifest=${JSON.stringify({
|
||||
entry: { module: "/assets/entry.client-A.js", imports: ["/assets/vendor-A.js"], css: [] },
|
||||
routes: { root: { id: "root", module: "/assets/root-A.js", imports: ["/assets/vendor-A.js"] } },
|
||||
})};`;
|
||||
stubAssets([
|
||||
{ name: "manifest-A.js", size: Buffer.byteLength(manifest), content: manifest },
|
||||
{ name: "entry.client-A.js", size: 30, content: 'import"./shared-A.js";void import("./lazy-A.js");' },
|
||||
{ name: "root-A.js", size: 20, content: 'import"./shared-A.js";' },
|
||||
{ name: "vendor-A.js", size: 10, content: "export const vendor = 1;" },
|
||||
{ name: "shared-A.js", size: 10, content: "export const shared = 1;" },
|
||||
{ name: "lazy-A.js", size: 10, content: "export const lazy = 1;" },
|
||||
]);
|
||||
|
||||
const measured = await measureInitialPayload({ assetsDir: "/tmp/assets" });
|
||||
expect(measured.names).toEqual(["entry.client-A.js", "manifest-A.js", "root-A.js", "shared-A.js", "vendor-A.js"]);
|
||||
expect(measured.rawSize).toBeGreaterThan(0);
|
||||
expect(measured.gzipSize).toBeGreaterThan(0);
|
||||
expect(measured.brotliSize).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("readAssetFiles", () => {
|
||||
it("returns null when the assets directory does not exist", async () => {
|
||||
fsState.readdir.mockRejectedValue(Object.assign(new Error("missing"), { code: "ENOENT" }));
|
||||
@@ -328,9 +397,7 @@ describe("runBundleSizeGate", () => {
|
||||
const outcome = await runBundleSizeGate({ assetsDir: "/tmp/assets", logger });
|
||||
|
||||
expect(outcome.failures.some((failure) => failure.group === "empty_js_chunks")).toBe(true);
|
||||
expect(outcome.unexpectedEmptyJsChunks).toEqual([
|
||||
{ name: "new-empty-route-ABC123.js", size: 0, baselineName: "new-empty-route" },
|
||||
]);
|
||||
expect(outcome.unexpectedEmptyJsChunks).toEqual([{ name: "new-empty-route-ABC123.js", size: 0, baselineName: "new-empty-route" }]);
|
||||
expect(logger.errors).toContain("FAIL empty_js_chunks unexpected=1");
|
||||
});
|
||||
});
|
||||
@@ -342,6 +409,7 @@ describe("per-route budget config", () => {
|
||||
expect(cfg.default.warningKb).toBeGreaterThan(0);
|
||||
expect(Object.keys(cfg.routes).length).toBeGreaterThanOrEqual(12);
|
||||
expect(Object.keys(cfg.vendorChunks).length).toBeGreaterThanOrEqual(3);
|
||||
expect(Object.keys(cfg.lazyRuntimeChunks).length).toBeGreaterThanOrEqual(8);
|
||||
});
|
||||
|
||||
it("pins emitted workflow chunk names to explicit budgets", () => {
|
||||
@@ -383,6 +451,8 @@ describe("isVendorChunkName / isRouteChunkName", () => {
|
||||
expect(isRouteChunkName("root-AAAA.js")).toBe(false);
|
||||
expect(isRouteChunkName("manifest-AAAA.js")).toBe(false);
|
||||
expect(isRouteChunkName("vendor-react-AAAA.js")).toBe(false);
|
||||
expect(isRouteChunkName("ts.worker-AAAA.js")).toBe(false);
|
||||
expect(isRouteChunkName("MonacoEditor.client-AAAA.js")).toBe(false);
|
||||
});
|
||||
it("includes route group + dynamic segment chunks", () => {
|
||||
expect(isRouteChunkName("(_lang)-AAAA.js")).toBe(true);
|
||||
@@ -405,6 +475,10 @@ describe("lookupBudget", () => {
|
||||
"vendor-editor-prosemirror": { limitKb: 150, warningKb: 135 },
|
||||
"vendor-misc": { limitKb: 300, warningKb: 280 },
|
||||
},
|
||||
lazyRuntimeChunks: {
|
||||
"MonacoEditor.client": { limitKb: 1_000, warningKb: 950 },
|
||||
"ts.worker": { limitKb: 1_550, warningKb: 1_520 },
|
||||
},
|
||||
};
|
||||
|
||||
it("matches vendor-chunk baseline keys to vendorChunks", () => {
|
||||
@@ -412,6 +486,24 @@ describe("lookupBudget", () => {
|
||||
expect(res).toEqual({ kind: "vendor", key: "vendor-react", budget: config.vendorChunks["vendor-react"] });
|
||||
});
|
||||
|
||||
it("matches self-hosted feature runtimes to dedicated budgets", () => {
|
||||
expect(lookupBudget("MonacoEditor.client", config)).toEqual({
|
||||
kind: "lazy-runtime",
|
||||
key: "MonacoEditor.client",
|
||||
budget: config.lazyRuntimeChunks["MonacoEditor.client"],
|
||||
});
|
||||
expect(lookupBudget("ts.worker", config)).toEqual({
|
||||
kind: "lazy-runtime",
|
||||
key: "ts.worker",
|
||||
budget: config.lazyRuntimeChunks["ts.worker"],
|
||||
});
|
||||
expect(lookupBudget("lazy-monaco-MonacoEditor.client", config)).toEqual({
|
||||
kind: "lazy-runtime",
|
||||
key: "MonacoEditor.client",
|
||||
budget: config.lazyRuntimeChunks["MonacoEditor.client"],
|
||||
});
|
||||
});
|
||||
|
||||
it("matches the longest configured vendor chunk key before falling back to a shorter prefix", () => {
|
||||
expect(lookupBudget("vendor-editor-tiptap", config)).toEqual({
|
||||
kind: "vendor",
|
||||
@@ -468,13 +560,7 @@ describe("classifyBudgetStatus", () => {
|
||||
|
||||
describe("summarizePerAssetEntries", () => {
|
||||
it("counts each status bucket", () => {
|
||||
const entries = [
|
||||
{ status: "ok" },
|
||||
{ status: "ok" },
|
||||
{ status: "warning" },
|
||||
{ status: "exceeds" },
|
||||
{ status: "unbudgeted" },
|
||||
];
|
||||
const entries = [{ status: "ok" }, { status: "ok" }, { status: "warning" }, { status: "exceeds" }, { status: "unbudgeted" }];
|
||||
expect(summarizePerAssetEntries(entries)).toEqual({ ok: 2, warning: 1, exceeds: 1, unbudgeted: 1 });
|
||||
});
|
||||
});
|
||||
@@ -497,7 +583,7 @@ describe("JSON report mode", () => {
|
||||
budget: { limitKb: 100, warningKb: 90 },
|
||||
},
|
||||
],
|
||||
}),
|
||||
})
|
||||
).toEqual({
|
||||
skipped: false,
|
||||
totals: { ok: 1, warning: 0, exceeds: 0, unbudgeted: 0 },
|
||||
@@ -525,7 +611,11 @@ describe("JSON report mode", () => {
|
||||
const exitCode = await runCli({
|
||||
args: ["--json"],
|
||||
logger,
|
||||
stdout: { write: (chunk) => { output += chunk; } },
|
||||
stdout: {
|
||||
write: (chunk) => {
|
||||
output += chunk;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(exitCode).toBe(0);
|
||||
@@ -550,7 +640,7 @@ describe("JSON report mode", () => {
|
||||
|
||||
expect(exitCode).toBe(0);
|
||||
expect(fsState.readdir).toHaveBeenCalledTimes(1);
|
||||
expect(fsState.stat).toHaveBeenCalledTimes(2);
|
||||
expect(fsState.stat).toHaveBeenCalledTimes(3);
|
||||
expect(logger.logs.some((line) => line.startsWith("Per-route summary:"))).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user