Skip to content

Commit

Permalink
refactor: Fix tests in Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte committed Apr 11, 2024
1 parent 583e026 commit 35b26d0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/linter/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ function resolveFilePaths(rootDir: string, filePaths: string[]): string[] {
});
}

function ensurePosix(inputPath: string) {
if (!inputPath.includes("\\")) {
return inputPath;
}
return inputPath.replace(/\\/g, "/");
}

/**
* Normalize provided filePaths to virtual paths.
* Returned paths are absolute, POSIX-style paths
Expand All @@ -202,9 +209,9 @@ function transformFilePathsToVirtualPaths(
): FilePath[] {
return filePaths.map((filePath) => {
if (filePath.startsWith(srcFsBasePath)) {
return posixPath.join(srcVirBasePath, path.relative(srcFsBasePath, filePath));
return posixPath.join(srcVirBasePath, ensurePosix(path.relative(srcFsBasePath, filePath)));
} else if (testFsBasePath && testVirBasePath && filePath.startsWith(testFsBasePath)) {
return posixPath.join(testVirBasePath, path.relative(testFsBasePath, filePath));
return posixPath.join(testVirBasePath, ensurePosix(path.relative(testFsBasePath, filePath)));
} else {
throw new Error(
`File path ${filePath} is not located within the detected source or test directories of the project`);
Expand Down

0 comments on commit 35b26d0

Please sign in to comment.