Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
TypeScript
123456789101112131415161718192021222324252627282930313233import { describe, expect, it } from "vitest";import { hardenAssetHeaders, REVALIDATED_IMMUTABLE } from "$lib/assetHeaders";
// what @sveltejs/adapter-cloudflare appends to the deployed _headersconst 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); });});