UNPKG

@inlang/paraglide-js

Version:

[![NPM Downloads](https://img.shields.io/npm/dw/%40inlang%2Fparaglide-js?logo=npm&logoColor=red&label=npm%20downloads)](https://www.npmjs.com/package/@inlang/paraglide-js) [![GitHub Issues](https://img.shields.io/github/issues-closed/opral/paraglide-js?lo

148 lines 5.11 kB
import { test, expect } from "vitest"; import { generateOutput } from "./message-modules.js"; test("should emit per locale message files", () => { const resources = [ { bundle: { code: 'console.log("bundle code");', node: { id: "happy_elephant", }, }, messages: { en: { code: 'console.log("message in English");', node: {}, }, de: { code: 'console.log("message in German");', node: {}, }, }, matchTypes: new Map(), }, ]; const settings = { locales: ["en", "de"], baseLocale: "en", }; const fallbackMap = { en: "de", de: "en", }; const output = generateOutput(resources, settings, fallbackMap); expect(output).not.toHaveProperty("messages/en.js"); expect(output).not.toHaveProperty("messages/de.js"); expect(output).toHaveProperty("messages/happy_elephant.js"); }); test("handles case senstivity by creating directories and files only in lowercase", () => { const resources = [ { bundle: { code: "export const HappyElephant = () => en.HappyElephant", node: { id: "HappyElephant", }, }, messages: { en: { code: 'export const HappyElephant = () => "HappyElephant0"', node: {}, }, }, matchTypes: new Map(), }, { bundle: { code: "export const happyelephant = () => en.happyelephant", node: { id: "happyelephant", }, }, messages: { en: { code: 'export const happyelephant = () => "happyelephant1"', node: {}, }, }, matchTypes: new Map(), }, ]; const settings = { locales: ["en"], baseLocale: "en", }; const output = generateOutput(resources, settings, {}); // expecting only lowercase directories and files expect(output).toHaveProperty("messages/happyelephant.js"); expect(output).toHaveProperty("messages/happyelephant2.js"); expect(output).not.toHaveProperty("messages/HappyElephant.js"); }); test("emits minimal runtime imports when middleware splitting is disabled", () => { const resources = [ { bundle: { code: "export const happy_elephant = () => en_happy_elephant()", node: { id: "happy_elephant", }, }, messages: { en: { code: '() => "happy"', node: {}, }, }, matchTypes: new Map(), }, ]; const output = generateOutput(resources, { locales: ["en"], baseLocale: "en" }, {}, false); expect(output["messages/happy_elephant.js"]).toContain("import { getLocale, experimentalStaticLocale } from '../runtime.js';"); expect(output["messages/happy_elephant.js"]).not.toContain("trackMessageCall"); expect(output["messages/happy_elephant.js"]).not.toContain("experimentalMiddlewareLocaleSplitting"); expect(output["messages/happy_elephant.js"]).not.toContain("isServer"); }); // Regression test for https://github.com/opral/inlang-paraglide-js/issues/507 test("emits fallback definitions after their dependencies", () => { const resources = [ { bundle: { code: "export const admin_tasks = (inputs) => inputs;", node: { id: "admin_tasks", declarations: [], }, }, messages: { en: { code: '/** @type {(inputs: {}) => string} */ () => "admin"', node: {}, }, }, matchTypes: new Map(), }, ]; const settings = { locales: ["fr-ca", "fr", "en"], baseLocale: "en", }; const fallbackMap = { "fr-ca": "fr", fr: "en", en: undefined, }; const output = generateOutput(resources, settings, fallbackMap); const file = output["messages/admin_tasks.js"]; expect(file).toBeDefined(); if (!file) { throw new Error("messages/admin_tasks.js should have been generated"); } expect(file).toContain("const fr_admin_tasks = en_admin_tasks;"); expect(file).toContain("const fr_ca_admin_tasks = fr_admin_tasks;"); const frIndex = file.indexOf("const fr_admin_tasks"); const frCaIndex = file.indexOf("const fr_ca_admin_tasks"); expect(frIndex).toBeGreaterThan(-1); expect(frCaIndex).toBeGreaterThan(-1); expect(frIndex).toBeLessThan(frCaIndex); }); //# sourceMappingURL=message-modules.test.js.map