fix(test): normalize path separators [skip ci]

This commit is contained in:
Vincent Koc
2026-03-21 17:32:23 -07:00
parent c449a0a3c1
commit 45f84cf639
2 changed files with 18 additions and 5 deletions

View File

@@ -50,6 +50,14 @@ export function collectFilesSync(
return files;
}
export function relativeToCwd(filePath: string): string {
return path.relative(process.cwd(), filePath) || filePath;
export function toPosixPath(filePath: string): string {
if (path.sep === "/") {
return filePath;
}
return filePath.replaceAll("\\", "/");
}
export function relativeToCwd(filePath: string): string {
const relativePath = path.relative(process.cwd(), filePath) || filePath;
return toPosixPath(relativePath);
}

View File

@@ -2,7 +2,12 @@ import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { collectFilesSync, isCodeFile, relativeToCwd } from "../../scripts/check-file-utils.js";
import {
collectFilesSync,
isCodeFile,
relativeToCwd,
toPosixPath,
} from "../../scripts/check-file-utils.js";
const tempDirs: string[] = [];
@@ -37,7 +42,7 @@ describe("scripts/check-file-utils collectFilesSync", () => {
const files = collectFilesSync(rootDir, {
includeFile: (filePath) => filePath.endsWith(".ts"),
}).map((filePath) => path.relative(rootDir, filePath));
}).map((filePath) => toPosixPath(path.relative(rootDir, filePath)));
expect(files.toSorted()).toEqual(["src/keep.ts", "src/nested/keep.test.ts"]);
});
@@ -52,7 +57,7 @@ describe("scripts/check-file-utils collectFilesSync", () => {
const files = collectFilesSync(rootDir, {
includeFile: (filePath) => filePath.endsWith(".ts"),
skipDirNames: new Set(["fixtures"]),
}).map((filePath) => path.relative(rootDir, filePath));
}).map((filePath) => toPosixPath(path.relative(rootDir, filePath)));
expect(files).toEqual(["src/keep.ts"]);
});