import { describe, expect, it } from "vitest"; import { hardenAssetHeaders, REVALIDATED_IMMUTABLE } from "$lib/assetHeaders"; // what @sveltejs/adapter-cloudflare appends to the deployed _headers const adapterHeaders = ` # === START AUTOGENERATED SVELTE IMMUTABLE HEADERS === /_app/* X-Robots-Tag: noindex Cache-Control: no-cache /_app/immutable/* ! Cache-Control Cache-Control: public, immutable, max-age=31536000 # === END AUTOGENERATED SVELTE IMMUTABLE HEADERS === `; describe("hardenAssetHeaders", () => { it("overrides the adapter's year-long rule from behind it", () => { const hardened = hardenAssetHeaders(adapterHeaders); expect(hardened.indexOf(REVALIDATED_IMMUTABLE)).toBeGreaterThan( hardened.indexOf("public, immutable, max-age=31536000") ); }); it("leaves the rest of the file alone", () => { expect(hardenAssetHeaders(adapterHeaders)).toContain("X-Robots-Tag: noindex"); }); it("is idempotent, so a rebuilt file grows no rules", () => { const once = hardenAssetHeaders(adapterHeaders); expect(hardenAssetHeaders(once)).toBe(once); }); });