Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/soft-melons-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"lingo.dev": patch
---

fix(cli): normalize path separators in tests for Windows
1 change: 1 addition & 0 deletions lingo.dev
Submodule lingo.dev added at 060680
15 changes: 11 additions & 4 deletions packages/cli/src/cli/utils/buckets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);

Expand All @@ -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: [
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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: "-" }],
Expand All @@ -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: [
Expand Down
15 changes: 11 additions & 4 deletions packages/cli/src/cli/utils/find-locale-paths.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"],
Expand All @@ -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"],
Expand All @@ -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"],
Expand Down Expand Up @@ -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: [
Expand Down
Loading