Initial Commit

This commit is contained in:
2026-05-27 23:47:53 +01:00
parent fbc70f96e6
commit 9b28db724f
18103 changed files with 1600554 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
import { describe, expect, it } from "@suaveplan/testing/runner";
import { CADDY_IMGPROXY_CODES, CaddyImgproxyError } from "./error-codes.js";
describe("CADDY_IMGPROXY_CODES", () => {
it("namespaces every code under CADDY_IMGPROXY.", { timeout: 5000 }, () => {
for (const value of Object.values(CADDY_IMGPROXY_CODES)) {
expect(value.startsWith("CADDY_IMGPROXY.")).toBe(true);
}
});
it("exposes the expected leaf names", { timeout: 5000 }, () => {
expect(Object.keys(CADDY_IMGPROXY_CODES).sort()).toEqual([
"INVALID_HOST",
"INVALID_KEY",
"INVALID_OPTIONS",
"INVALID_SALT",
"INVALID_URL",
"MISSING_DIMENSIONS",
]);
});
it("carries the supplied code, message, cause, and context", {
timeout: 5000,
}, () => {
const cause = new Error("upstream");
const err = new CaddyImgproxyError(
CADDY_IMGPROXY_CODES.INVALID_URL,
"bad url",
{ cause, context: { path: "/x" } }
);
expect(err).toBeInstanceOf(CaddyImgproxyError);
expect(err.code).toBe(CADDY_IMGPROXY_CODES.INVALID_URL);
expect(err.message).toBe("bad url");
expect(err.cause).toBe(cause);
expect(err.context).toEqual({ path: "/x" });
expect(err.name).toBe("CaddyImgproxyError");
});
it("every registered code is thrown from at least one call site", {
timeout: 5000,
}, async () => {
// INVALID_URL — from parse-url
// MISSING_DIMENSIONS — from parse-url
// INVALID_OPTIONS — from config
// INVALID_KEY — from config / signing
// INVALID_SALT — from config / signing
// INVALID_HOST — from handler
// Each is exercised by its own test file; this reachability
// gate just confirms the registry has the expected closure.
const expected = new Set([
"CADDY_IMGPROXY.INVALID_URL",
"CADDY_IMGPROXY.MISSING_DIMENSIONS",
"CADDY_IMGPROXY.INVALID_OPTIONS",
"CADDY_IMGPROXY.INVALID_KEY",
"CADDY_IMGPROXY.INVALID_SALT",
"CADDY_IMGPROXY.INVALID_HOST",
]);
const actual = new Set(Object.values(CADDY_IMGPROXY_CODES));
expect(actual).toEqual(expected);
});
});