fix(custom-widgets): address v2 merge review
This commit is contained in:
1 parent
6aceb2fd1f
commit
48ce83806d
122 files changed
+8534
-1447
No files matched your search
@@ -5,6 +5,9 @@ import { basename, join, relative, resolve } from "node:path";
|
||||
const repositoryRoot = resolve(import.meta.dirname, "..");
|
||||
const nextRoot = join(repositoryRoot, "apps/nextjs/.next");
|
||||
const budgetBytes = Number(process.env.CUSTOM_WIDGET_CHUNK_BUDGET_BYTES ?? 768 * 1024);
|
||||
if (!Number.isSafeInteger(budgetBytes) || budgetBytes <= 0) {
|
||||
throw new Error("CUSTOM_WIDGET_CHUNK_BUDGET_BYTES must be a positive integer.");
|
||||
}
|
||||
|
||||
async function collect(directory, predicate) {
|
||||
const result = [];
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// @vitest-environment node
|
||||
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
describe("Custom Widget bundle budget", () => {
|
||||
test.each(["not-a-number", "0", "-1", "1.5", String(Number.MAX_SAFE_INTEGER + 1)])(
|
||||
"rejects an invalid byte budget (%s)",
|
||||
(budget) => {
|
||||
const result = spawnSync(process.execPath, ["scripts/check-custom-widget-bundle.mjs"], {
|
||||
cwd: process.cwd(),
|
||||
encoding: "utf8",
|
||||
env: { ...process.env, CUSTOM_WIDGET_CHUNK_BUDGET_BYTES: budget },
|
||||
});
|
||||
|
||||
expect(result.status).not.toBe(0);
|
||||
expect(result.stderr).toContain("CUSTOM_WIDGET_CHUNK_BUDGET_BYTES must be a positive integer");
|
||||
expect(result.stderr).not.toContain("Next.js build output is missing");
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
|
||||
import { openApiDocument } from "@homarr/api/open-api";
|
||||
|
||||
const baseUrl = "http://localhost:3000";
|
||||
const generated = JSON.parse(JSON.stringify(openApiDocument(baseUrl))) as unknown;
|
||||
const checkedIn = JSON.parse(await readFile("apps/docs/static/api/open-api-schema.json", "utf8")) as unknown;
|
||||
|
||||
try {
|
||||
assert.deepStrictEqual(checkedIn, generated);
|
||||
} catch {
|
||||
console.error(
|
||||
"The checked-in OpenAPI schema is stale. Regenerate it from openApiDocument and update apps/docs/static/api/open-api-schema.json.",
|
||||
);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
Reference in new issue
Block a user