|
| 1 | +import { testClient } from "@hono/hono/testing"; |
| 2 | +import { expect } from "@std/expect"; |
| 3 | +import { describe, it } from "node:test"; |
| 4 | +import { app } from "../example/main.tsx"; |
| 5 | + |
| 6 | +const testApp = testClient(app); |
| 7 | + |
| 8 | +describe("Hono + Honolate E2E", () => { |
| 9 | + describe("t function in different contexts", () => { |
| 10 | + const paths = [ |
| 11 | + "text", |
| 12 | + "render", |
| 13 | + "component", |
| 14 | + "async-component", |
| 15 | + "async-component-alt", |
| 16 | + ] as const; |
| 17 | + for (const path of paths) { |
| 18 | + it(`GET /${path} should return localized 'Hello world!'`, async () => { |
| 19 | + const resDefault = await (await testApp[path].$get({})).text(); |
| 20 | + const resEn = await (await testApp[path].$get({ |
| 21 | + query: { lang: "en" }, |
| 22 | + })).text(); |
| 23 | + const resDe = await (await testApp[path].$get({ |
| 24 | + query: { lang: "de" }, |
| 25 | + })).text(); |
| 26 | + |
| 27 | + expect(resDefault).toContain("Hello world!"); |
| 28 | + expect(resEn).toContain("Hello world!"); |
| 29 | + expect(resDe).toContain("Hallo Welt!"); |
| 30 | + }); |
| 31 | + } |
| 32 | + }); |
| 33 | + describe("Untranslated text", () => { |
| 34 | + it("GET /untranslated should return untranslated text", async () => { |
| 35 | + const resDefault = await (await testApp.untranslated.$get({})).text(); |
| 36 | + const resEn = await (await testApp.untranslated.$get({ |
| 37 | + query: { lang: "en" }, |
| 38 | + })).text(); |
| 39 | + const resDe = await (await testApp.untranslated.$get({ |
| 40 | + query: { lang: "de" }, |
| 41 | + })).text(); |
| 42 | + |
| 43 | + expect(resDefault).toBe("Untranslated text"); |
| 44 | + expect(resEn).toBe("Untranslated text"); |
| 45 | + expect(resDe).toBe("Untranslated text"); |
| 46 | + }); |
| 47 | + }); |
| 48 | + describe("Lazy translation term", () => { |
| 49 | + it("GET /lazy should return localized lazy term", async () => { |
| 50 | + const resDefault = await (await testApp.lazy.$get({})).text(); |
| 51 | + const resEn = await (await testApp.lazy.$get({ |
| 52 | + query: { lang: "en" }, |
| 53 | + })).text(); |
| 54 | + const resDe = await (await testApp.lazy.$get({ |
| 55 | + query: { lang: "de" }, |
| 56 | + })).text(); |
| 57 | + |
| 58 | + expect(resDefault).toBe("Lazy term"); |
| 59 | + expect(resEn).toBe("Lazy term"); |
| 60 | + expect(resDe).toBe("Fauler Begriff"); |
| 61 | + }); |
| 62 | + }); |
| 63 | + describe("Escape test", () => { |
| 64 | + it("GET /escape-test should return correctly escaped text", async () => { |
| 65 | + const res = await (await testApp["escape-test"].$get({})).text(); |
| 66 | + expect(res).toBe("This text contains 1 {} curly braces and \\{{}}{0}."); |
| 67 | + const resDe = await (await testApp["escape-test"].$get({ |
| 68 | + query: { lang: "de" }, |
| 69 | + })).text(); |
| 70 | + expect(resDe).toBe( |
| 71 | + "Dieser Text enthält 1 {} geschweifte Klammern und \\{{}}{0}.", |
| 72 | + ); |
| 73 | + }); |
| 74 | + }); |
| 75 | + describe("Locale", () => { |
| 76 | + it("GET /locale should return correct locale", async () => { |
| 77 | + const resDefault = await (await testApp.locale.$get({})).text(); |
| 78 | + const resEn = await (await testApp.locale.$get({ |
| 79 | + query: { lang: "en" }, |
| 80 | + })).text(); |
| 81 | + const resDe = await (await testApp.locale.$get({ |
| 82 | + query: { lang: "de" }, |
| 83 | + })).text(); |
| 84 | + |
| 85 | + expect(resDefault).toBe("en"); |
| 86 | + expect(resEn).toBe("en"); |
| 87 | + expect(resDe).toBe("de"); |
| 88 | + }); |
| 89 | + }); |
| 90 | +}); |
0 commit comments