From 086d3fa8fa380708d488ef0151cde4b9545e544e Mon Sep 17 00:00:00 2001 From: uwx Date: Wed, 8 Oct 2025 12:53:32 +0200 Subject: [PATCH] Fix tests on Windows filesystems --- packages/emitter/test/integration.test.ts | 12 +++++++++--- packages/emitter/test/spec.test.ts | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/emitter/test/integration.test.ts b/packages/emitter/test/integration.test.ts index 69a599a..894d0ab 100644 --- a/packages/emitter/test/integration.test.ts +++ b/packages/emitter/test/integration.test.ts @@ -64,7 +64,7 @@ describe("lexicon scenarios", function () { // Create a virtual main.tsp that imports all other files const mainContent = 'import "@typelex/emitter";\n' + - tspFiles.map((f) => `import "./${f}";`).join("\n"); + tspFiles.map((f) => `import "./${normalizePathToPosix(f)}";`).join("\n"); const filesWithMain = { ...inputFiles, "main.tsp": mainContent }; emitResult = await doEmit(filesWithMain, "main.tsp"); } else { @@ -91,15 +91,17 @@ describe("lexicon scenarios", function () { ); } + const normalizedExpectedPath = normalizePathToPosix(expectedPath); + assert.ok( Object.prototype.hasOwnProperty.call( emitResult.files, - expectedPath, + normalizedExpectedPath, ), `Expected file ${expectedPath} was not produced`, ); - const actual = JSON.parse(emitResult.files[expectedPath]); + const actual = JSON.parse(emitResult.files[normalizedExpectedPath]); const expected = JSON.parse(expectedFiles[expectedPath]); assert.deepStrictEqual(actual, expected); }); @@ -180,3 +182,7 @@ async function readdirRecursive(dir: string): Promise> { await walk(dir, ""); return result; } + +function normalizePathToPosix(thePath: string): string { + return thePath.replaceAll(path.sep, path.posix.sep); +} \ No newline at end of file diff --git a/packages/emitter/test/spec.test.ts b/packages/emitter/test/spec.test.ts index 53a69d3..1c52edb 100644 --- a/packages/emitter/test/spec.test.ts +++ b/packages/emitter/test/spec.test.ts @@ -64,7 +64,7 @@ describe("lexicon spec", function () { // Create a virtual main.tsp that imports all other files const mainContent = 'import "@typelex/emitter";\n' + - tspFiles.map((f) => `import "./${f}";`).join("\n"); + tspFiles.map((f) => `import "./${normalizePathToPosix(f)}";`).join("\n"); const filesWithMain = { ...inputFiles, "main.tsp": mainContent }; emitResult = await doEmit(filesWithMain, "main.tsp"); } else { @@ -91,15 +91,17 @@ describe("lexicon spec", function () { ); } + const normalizedExpectedPath = normalizePathToPosix(expectedPath); + assert.ok( Object.prototype.hasOwnProperty.call( emitResult.files, - expectedPath, + normalizedExpectedPath, ), `Expected file ${expectedPath} was not produced`, ); - const actual = JSON.parse(emitResult.files[expectedPath]); + const actual = JSON.parse(emitResult.files[normalizedExpectedPath]); const expected = JSON.parse(expectedFiles[expectedPath]); assert.deepStrictEqual(actual, expected); }); @@ -180,3 +182,7 @@ async function readdirRecursive(dir: string): Promise> { await walk(dir, ""); return result; } + +function normalizePathToPosix(thePath: string): string { + return thePath.replaceAll(path.sep, path.posix.sep); +} \ No newline at end of file -- 2.43.0