Fix tests on Windows filesystems #1

readdirRecursive returns backslash-separated paths on Windows whereas typespec expects forward slash separated paths. This PR normalizes them.

Changed files
+18 -6
packages
+9 -3
packages/emitter/test/integration.test.ts
···
// 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 {
···
);
}
+
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);
});
···
await walk(dir, "");
return result;
}
+
+
function normalizePathToPosix(thePath: string): string {
+
return thePath.replaceAll(path.sep, path.posix.sep);
+
}
+9 -3
packages/emitter/test/spec.test.ts
···
// 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 {
···
);
}
+
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);
});
···
await walk(dir, "");
return result;
}
+
+
function normalizePathToPosix(thePath: string): string {
+
return thePath.replaceAll(path.sep, path.posix.sep);
+
}