@multiplatform.one/i18n 6.0.4 → 6.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,65 +0,0 @@
1
- import { describe, expect, it, beforeEach, afterEach } from "vitest";
2
- import { getPersistedLanguage, persistLanguage, parseCookieValue } from "../src/localePersistence";
3
-
4
- describe("localePersistence", () => {
5
- // Test 1: Cookie set/get roundtrip with preferred_language
6
- describe("cookie roundtrip", () => {
7
- let originalDocument: typeof globalThis.document;
8
-
9
- beforeEach(() => {
10
- // Mock document.cookie for Node.js test environment
11
- originalDocument = globalThis.document;
12
- let cookieStore = "";
13
- Object.defineProperty(globalThis, "document", {
14
- value: {
15
- get cookie() {
16
- return cookieStore;
17
- },
18
- set cookie(val: string) {
19
- // Simple cookie store: accumulate cookies separated by '; '
20
- const name = val.split("=")[0];
21
- const parts = cookieStore.split("; ").filter((c) => !c.startsWith(`${name}=`));
22
- parts.push(val.split(";")[0]);
23
- cookieStore = parts.filter(Boolean).join("; ");
24
- },
25
- },
26
- writable: true,
27
- configurable: true,
28
- });
29
- });
30
-
31
- afterEach(() => {
32
- Object.defineProperty(globalThis, "document", {
33
- value: originalDocument,
34
- writable: true,
35
- configurable: true,
36
- });
37
- });
38
-
39
- it("persists and reads back a language cookie", () => {
40
- expect(getPersistedLanguage()).toBeNull();
41
- persistLanguage("es");
42
- expect(getPersistedLanguage()).toBe("es");
43
- persistLanguage("te");
44
- expect(getPersistedLanguage()).toBe("te");
45
- });
46
- });
47
-
48
- describe("parseCookieValue", () => {
49
- it("extracts a named cookie from a header string", () => {
50
- const header = "session_id=abc123; preferred_language=fr; theme=dark";
51
- expect(parseCookieValue(header, "preferred_language")).toBe("fr");
52
- expect(parseCookieValue(header, "session_id")).toBe("abc123");
53
- expect(parseCookieValue(header, "theme")).toBe("dark");
54
- });
55
-
56
- it("returns null for missing cookie", () => {
57
- expect(parseCookieValue("session_id=abc", "preferred_language")).toBeNull();
58
- expect(parseCookieValue("", "preferred_language")).toBeNull();
59
- });
60
-
61
- it("decodes URI-encoded values", () => {
62
- expect(parseCookieValue("preferred_language=zh-CN", "preferred_language")).toBe("zh-CN");
63
- });
64
- });
65
- });
@@ -1,25 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { execSync } from "node:child_process";
3
- import path from "node:path";
4
-
5
- const rootdir = path.resolve(__dirname, "../../..");
6
-
7
- describe("make.mk FRAPPE_APP_EXISTS flag", () => {
8
- // Test 1: Verify the Makefile variable detects apps/frappe directory presence
9
- it("sets VITE_FRAPPE_ENABLED=true when apps/frappe exists", () => {
10
- // Use --eval to print the evaluated variable value
11
- const result = execSync(
12
- `make -f make.mk rootdir=${rootdir} --eval='print-flag: ; @echo $(VITE_FRAPPE_ENABLED)' print-flag 2>/dev/null`,
13
- { cwd: rootdir, encoding: "utf-8", env: { ...process.env, VITE_FRAPPE_ENABLED: undefined } },
14
- ).trim();
15
- expect(result).toBe("true");
16
- });
17
-
18
- it("FRAPPE_APP_EXISTS reflects directory presence", () => {
19
- const result = execSync(
20
- `make -f make.mk rootdir=${rootdir} --eval='print-flag: ; @echo $(FRAPPE_APP_EXISTS)' print-flag 2>/dev/null`,
21
- { cwd: rootdir, encoding: "utf-8" },
22
- ).trim();
23
- expect(result).toBe("true");
24
- });
25
- });
@@ -1,74 +0,0 @@
1
- import { describe, expect, it, beforeEach, afterEach } from "vitest";
2
-
3
- // Test 4: useLanguage persists to cookie when language changes
4
- // We test the integration by verifying that persistLanguage is called
5
- // when the changeLanguage callback is invoked.
6
- describe("useLanguage persistence", () => {
7
- let cookieStore: string;
8
-
9
- beforeEach(() => {
10
- cookieStore = "";
11
- Object.defineProperty(globalThis, "document", {
12
- value: {
13
- get cookie() {
14
- return cookieStore;
15
- },
16
- set cookie(val: string) {
17
- const name = val.split("=")[0];
18
- const parts = cookieStore.split("; ").filter((c) => c && !c.startsWith(`${name}=`));
19
- parts.push(val.split(";")[0]);
20
- cookieStore = parts.filter(Boolean).join("; ");
21
- },
22
- },
23
- writable: true,
24
- configurable: true,
25
- });
26
- });
27
-
28
- afterEach(() => {
29
- Object.defineProperty(globalThis, "document", {
30
- value: undefined,
31
- writable: true,
32
- configurable: true,
33
- });
34
- });
35
-
36
- it("persistLanguage sets the preferred_language cookie", async () => {
37
- const { persistLanguage, getPersistedLanguage } = await import("../src/locale_persistence");
38
-
39
- // Before: no cookie
40
- expect(getPersistedLanguage()).toBeNull();
41
-
42
- // Simulate what useLanguage does when setLanguage is called
43
- persistLanguage("es");
44
- expect(getPersistedLanguage()).toBe("es");
45
-
46
- // Change again
47
- persistLanguage("de");
48
- expect(getPersistedLanguage()).toBe("de");
49
- });
50
-
51
- it("cookie string contains correct attributes", async () => {
52
- const { persistLanguage } = await import("../src/locale_persistence");
53
- // Capture the raw cookie string set on document
54
- let lastCookie = "";
55
- Object.defineProperty(globalThis, "document", {
56
- value: {
57
- get cookie() {
58
- return cookieStore;
59
- },
60
- set cookie(val: string) {
61
- lastCookie = val;
62
- },
63
- },
64
- writable: true,
65
- configurable: true,
66
- });
67
-
68
- persistLanguage("fr");
69
- expect(lastCookie).toContain("preferred_language=fr");
70
- expect(lastCookie).toContain("path=/");
71
- expect(lastCookie).toContain("max-age=");
72
- expect(lastCookie).toContain("samesite=lax");
73
- });
74
- });
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "extends": "../../tsconfig.base.json",
4
- "compilerOptions": {
5
- "composite": false,
6
- "noEmit": true
7
- },
8
- "include": ["src/**/*"],
9
- "exclude": ["node_modules"],
10
- "references": []
11
- }
package/vitest.config.mjs DELETED
@@ -1,13 +0,0 @@
1
- import { defineConfig } from "vitest/config";
2
-
3
- // Ensure VITE_FRAPPE_ENABLED is "false" in test env by default
4
- process.env.VITE_FRAPPE_ENABLED = "false";
5
-
6
- export default defineConfig({
7
- test: {
8
- environment: "jsdom",
9
- testTimeout: 10000,
10
- include: ["tests/**/*.test.{ts,tsx}", "src/**/*.spec.{ts,tsx}"],
11
- exclude: ["**/node_modules/**", "**/dist/**"],
12
- },
13
- });