test(dev-server): guard server-rendered translations

This commit is contained in:
2026-08-09 13:22:18 +05:30
parent b2e83bc941
commit 91e8b2ab05
@@ -3,6 +3,7 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { basename, join } from "node:path";
import { tmpdir } from "node:os";
import { buildRouter } from "@wrnexus/router";
import { resolveI18n } from "@wrnexus/i18n";
import { createHandlers, type RuntimeDeps } from "../src/runtime.ts";
const roots: string[] = [];
@@ -45,3 +46,29 @@ test("a component nested in another component's slot keeps its boundary", async
expect(html).toContain('<b class="badge">x</b>');
expect(html).not.toContain('data-component="Badge"');
});
test("translated text is present in the raw server response", async () => {
const root = mkdtempSync(join(tmpdir(), "wrnexus-ssr-i18n-"));
roots.push(root);
const app = join(root, "app");
mkdirSync(join(app, "pages"), { recursive: true });
writeFileSync(join(app, "pages/index.ts"), "export default () => '';\n");
const handlers = createHandlers({
mode: "development",
hmr: false,
router: buildRouter(app),
i18n: resolveI18n({ en: { nav: { title: "Navigation" } } }, { default: "en" }),
loadModule: async () => ({
default: () => '<nav><span data-t="nav.title"></span></nav>',
}),
getMiddleware: async () => [],
assets: { serve: async () => null },
} satisfies RuntimeDeps);
const response = await handlers.fetch(new Request("https://example.test/"), {
upgrade: () => false,
});
const html = await response!.text();
expect(html).toContain('<span data-t="nav.title">Navigation</span>');
});