diff --git a/.changeset/soft-melons-sin.md b/.changeset/soft-melons-sin.md new file mode 100644 index 000000000..b5eea244c --- /dev/null +++ b/.changeset/soft-melons-sin.md @@ -0,0 +1,5 @@ +--- +"lingo.dev": patch +--- + +fix(cli): normalize path separators in tests for Windows diff --git a/lingo.dev b/lingo.dev new file mode 160000 index 000000000..060680cd1 --- /dev/null +++ b/lingo.dev @@ -0,0 +1 @@ +Subproject commit 060680cd13c05dd77dd9d5447c064d948bd21cb0 diff --git a/packages/cli/src/cli/utils/buckets.spec.ts b/packages/cli/src/cli/utils/buckets.spec.ts index ec2be41fb..0ca0f9688 100644 --- a/packages/cli/src/cli/utils/buckets.spec.ts +++ b/packages/cli/src/cli/utils/buckets.spec.ts @@ -23,6 +23,13 @@ describe("getBuckets", () => { }, }); + const toPosix = (s: string) => s.replace(/\\/g, "/"); + const normalizeBuckets = (buckets: any) => + buckets.map((b: any) => ({ + type: b.type, + paths: b.paths.map((p: any) => ({ ...p, pathPattern: toPosix(p.pathPattern) })), + })); + it("should return correct buckets", () => { mockGlobSync(["src/i18n/en.json"], ["src/translations/en/messages.json"]); @@ -31,7 +38,7 @@ describe("getBuckets", () => { "src/translations/[locale]/messages.json", ]); const buckets = getBuckets(i18nConfig); - expect(buckets).toEqual([ + expect(normalizeBuckets(buckets)).toEqual([ { type: "json", paths: [ @@ -76,7 +83,7 @@ describe("getBuckets", () => { "src/i18n/data-*-[locale]-*/[locale].*.json", ]); const buckets = getBuckets(i18nConfig); - expect(buckets).toEqual([ + expect(normalizeBuckets(buckets)).toEqual([ { type: "json", paths: [ @@ -136,7 +143,7 @@ describe("getBuckets", () => { { path: "src/i18n/[locale].json", delimiter: "-" }, ]); const buckets = getBuckets(i18nConfig); - expect(buckets).toEqual([ + expect(normalizeBuckets(buckets)).toEqual([ { type: "json", paths: [{ pathPattern: "src/i18n/[locale].json", delimiter: "-" }], @@ -154,7 +161,7 @@ describe("getBuckets", () => { "src/[locale]/translations/[locale]/messages.json", ]); const buckets = getBuckets(i18nConfig); - expect(buckets).toEqual([ + expect(normalizeBuckets(buckets)).toEqual([ { type: "json", paths: [ diff --git a/packages/cli/src/cli/utils/find-locale-paths.spec.ts b/packages/cli/src/cli/utils/find-locale-paths.spec.ts index 0362081e5..92d9050da 100644 --- a/packages/cli/src/cli/utils/find-locale-paths.spec.ts +++ b/packages/cli/src/cli/utils/find-locale-paths.spec.ts @@ -13,6 +13,13 @@ describe("findLocaleFiles", () => { vi.clearAllMocks(); }); + const toPosix = (s: string) => s.replace(/\\/g, "/"); + const normalize = (r: { patterns: string[]; defaultPatterns: string[] } | null) => + r && { + patterns: r.patterns.map(toPosix), + defaultPatterns: r.defaultPatterns.map(toPosix), + }; + it("should find json locale files", () => { vi.mocked(glob.sync).mockReturnValue([ // valid locales @@ -26,7 +33,7 @@ describe("findLocaleFiles", () => { "src/settings.json", ]); - const result = findLocaleFiles("json"); + const result = normalize(findLocaleFiles("json")); expect(result).toEqual({ patterns: ["src/i18n/[locale].json", "src/translations/[locale].json"], @@ -41,7 +48,7 @@ describe("findLocaleFiles", () => { "translations/es.yml", ]); - const result = findLocaleFiles("yaml"); + const result = normalize(findLocaleFiles("yaml")); expect(result).toEqual({ patterns: ["locales/[locale].yml", "translations/[locale].yml"], @@ -56,7 +63,7 @@ describe("findLocaleFiles", () => { "lib/translations/fr.arb", ]); - const result = findLocaleFiles("flutter"); + const result = normalize(findLocaleFiles("flutter")); expect(result).toEqual({ patterns: ["lib/l10n/[locale].arb", "lib/translations/[locale].arb"], @@ -124,7 +131,7 @@ describe("findLocaleFiles", () => { "ios/MyApp/xx/Localizable.xcstrings", ]); - const result = findLocaleFiles("xcode-xcstrings"); + const result = normalize(findLocaleFiles("xcode-xcstrings")); expect(result).toEqual({ patterns: [