import { expect, test } from "bun:test"; import { I18N_RUNTIME, renderI18nData, renderI18nDataTag, resolveI18n } from "../src/index.ts"; const i18n = resolveI18n({ en: { hello: "Hello" }, es: { hello: "Hola" } }, { default: "en" }); test("the i18n payload is plain JSON, not an assignment", () => { const data = renderI18nData(i18n, "en"); expect(() => JSON.parse(data)).not.toThrow(); expect(data).not.toContain("window.__wrnI18n"); }); test("the data tag is a non-executable JSON block", () => { // An executable inline script is subject to script-src and gets blocked // whenever the document's CSP nonce came from a different response, which is // what left window.__wrnI18n undefined. A JSON block is never executed. const tag = renderI18nDataTag(i18n, "es"); expect(tag).toContain('type="application/json"'); expect(tag).toContain("data-wrn-i18n"); expect(tag).not.toContain("nonce="); expect(tag).toContain("Hola"); }); test("the i18n runtime reads the data block instead of relying on an inline assignment", () => { expect(I18N_RUNTIME).toContain('script[type="application/json"][data-wrn-i18n]'); });