fix(perf): enforce route budgets and ratchet coverage thresholds
CI / check (push) Successful in 31s
CI / tests-integration (push) Successful in 2m4s
CI / tests-unit (push) Successful in 2m16s
CI / tests-imaging-browsers (push) Successful in 1m30s
CI / tests-quality (push) Successful in 54s
CI / tests-ui (push) Successful in 3m1s
CI / preflight (push) Skipped
CI / deploy (push) Successful in 3m24s
CI / check (push) Successful in 31s
CI / tests-integration (push) Successful in 2m4s
CI / tests-unit (push) Successful in 2m16s
CI / tests-imaging-browsers (push) Successful in 1m30s
CI / tests-quality (push) Successful in 54s
CI / tests-ui (push) Successful in 3m1s
CI / preflight (push) Skipped
CI / deploy (push) Successful in 3m24s
Allow mode: enforce in the report config, fail the command on over-budget and unavailable routes, and make the markdown wording follow the configured mode. Recalibrate the budgets against the webpack build (baseline x1.15, rounded up to the next 10 KiB) now that the old Turbopack numbers no longer apply, so the Docker image build gate blocks genuine bundle regressions instead of only warning. Raise the Vitest coverage thresholds to the measured floor (37.17/30.1/31.79/38.17 -> 36/29/30/37).
This commit is contained in:
1 parent
e70b96e3a7
commit
3a296551f6
5 files changed
+100
-33
No files matched your search
@@ -373,7 +373,10 @@ describe("route JS measurement", () => {
|
||||
expect(() =>
|
||||
validateBudgets({ ...config, routes: [budget, budget] }),
|
||||
).toThrow();
|
||||
expect(() => validateBudgets({ ...config, mode: "enforce" })).toThrow();
|
||||
expect(validateBudgets({ ...config, mode: "enforce" }).mode).toBe(
|
||||
"enforce",
|
||||
);
|
||||
expect(() => validateBudgets({ ...config, mode: "strict" })).toThrow();
|
||||
expect(() => validateBudgets({ ...config, typo: true })).toThrow();
|
||||
});
|
||||
it("emits warnings and artifacts with exit zero when a build is unavailable", () => {
|
||||
@@ -423,4 +426,51 @@ describe("route JS measurement", () => {
|
||||
expect(markdown).toContain("not measured browser traffic");
|
||||
expect(markdown).toContain("Raw bytes");
|
||||
});
|
||||
describe("enforce mode", () => {
|
||||
const run = (dir, budgets) => {
|
||||
const write = (relative, value) => {
|
||||
const file = path.join(dir, relative);
|
||||
mkdirSync(path.dirname(file), { recursive: true });
|
||||
writeFileSync(file, JSON.stringify(value));
|
||||
};
|
||||
write("budgets.json", budgets);
|
||||
return spawnSync(
|
||||
process.execPath,
|
||||
[
|
||||
"scripts/performance-report.mjs",
|
||||
"--next-dir",
|
||||
dir,
|
||||
"--config",
|
||||
path.join(dir, "budgets.json"),
|
||||
"--output-dir",
|
||||
path.join(dir, "reports"),
|
||||
],
|
||||
{ encoding: "utf8" },
|
||||
);
|
||||
};
|
||||
it("passes when every route is measured within budget", () => {
|
||||
const enforce = { ...config, mode: "enforce" };
|
||||
const runResult = run(fixture().dir, enforce);
|
||||
expect(runResult.status).toBe(0);
|
||||
expect(runResult.stdout).toContain("Mode: enforce");
|
||||
expect(runResult.stderr).not.toContain("Performance budgets enforced");
|
||||
});
|
||||
it("fails when a route is over budget", () => {
|
||||
const enforce = {
|
||||
schemaVersion: 1,
|
||||
mode: "enforce",
|
||||
routes: [{ ...budget, maxInitialRawBytes: 1, maxInitialGzipBytes: 1 }],
|
||||
};
|
||||
const runResult = run(fixture().dir, enforce);
|
||||
expect(runResult.status).toBe(1);
|
||||
expect(runResult.stderr).toContain("Performance budgets enforced");
|
||||
expect(runResult.stderr).toContain("/news (over-budget)");
|
||||
});
|
||||
it("fails when a route cannot be measured, so broken manifests do not pass quietly", () => {
|
||||
const enforce = { ...config, mode: "enforce" };
|
||||
const runResult = run(path.join(fixture().dir, "missing"), enforce);
|
||||
expect(runResult.status).toBe(1);
|
||||
expect(runResult.stderr).toContain("/news (unavailable)");
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user