diff --git a/packages/header-analysis/package.json b/packages/header-analysis/package.json index 7b78a259..ac5d1eef 100644 --- a/packages/header-analysis/package.json +++ b/packages/header-analysis/package.json @@ -6,10 +6,14 @@ "license": "ISC", "author": "", "main": "src/index.ts", - "scripts": {}, + "scripts": { + "test": "bun test", + "test:watch": "bun test --watch" + }, "dependencies": {}, "devDependencies": { "@openstatus/tsconfig": "workspace:*", + "@types/bun": "latest", "typescript": "catalog:" } } diff --git a/packages/header-analysis/src/parser/x-vercel-cache.test.ts b/packages/header-analysis/src/parser/x-vercel-cache.test.ts new file mode 100644 index 00000000..eb464af7 --- /dev/null +++ b/packages/header-analysis/src/parser/x-vercel-cache.test.ts @@ -0,0 +1,30 @@ +import { describe, expect, it } from "bun:test"; + +import { parseXVercelCache } from "./x-vercel-cache"; + +describe("parseXVercelCache", () => { + it.each([ + ["MISS", "The response was not found in the edge cache"], + ["HIT", "The response was served from the edge cache."], + ["STALE", "A background request to the origin server"], + ["PRERENDER", "The response was served from static storage."], + ["REVALIDATED", "the cache was refreshed"], + ])("describes the documented state %p", (value, expectedFragment) => { + const result = parseXVercelCache(value); + expect(result.value).toBe(value); + expect(result.description).toContain(expectedFragment); + }); + + it("matches states case-insensitively", () => { + const lower = parseXVercelCache("revalidated"); + const upper = parseXVercelCache("REVALIDATED"); + expect(lower.description).toBe(upper.description); + expect(lower.description).not.toBe("-"); + }); + + it("falls back to '-' for an unknown value", () => { + const result = parseXVercelCache("UNKNOWN"); + expect(result.value).toBe("UNKNOWN"); + expect(result.description).toBe("-"); + }); +}); diff --git a/packages/header-analysis/src/parser/x-vercel-cache.ts b/packages/header-analysis/src/parser/x-vercel-cache.ts index 964f6de7..151295df 100644 --- a/packages/header-analysis/src/parser/x-vercel-cache.ts +++ b/packages/header-analysis/src/parser/x-vercel-cache.ts @@ -18,7 +18,7 @@ function getCacheDescription(key: string): string { return "The response was served from the edge cache. A background request to the origin server was made to update the content."; case "PRERENDER": return "The response was served from static storage."; - case "REVLIDATED": + case "REVALIDATED": return "The response was served from the origin server and the cache was refreshed due to an authorization from the user in the incoming request."; default: return "-"; diff --git a/packages/header-analysis/tsconfig.json b/packages/header-analysis/tsconfig.json index 48baa5cf..fad7f99b 100644 --- a/packages/header-analysis/tsconfig.json +++ b/packages/header-analysis/tsconfig.json @@ -2,6 +2,7 @@ "extends": "@openstatus/tsconfig/base.json", "include": ["src", "*.ts"], "compilerOptions": { - "resolveJsonModule": true + "resolveJsonModule": true, + "types": ["bun"] } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 93b86298..c0a3f9b6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1970,6 +1970,9 @@ importers: '@openstatus/tsconfig': specifier: workspace:* version: link:../tsconfig + '@types/bun': + specifier: latest + version: 1.3.14 typescript: specifier: 'catalog:' version: 5.9.3