8000 test: fix case-insensitive path matching on Windows by mcollina · Pull Request #61682 · nodejs/node · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
< 10062 /include-fragment>
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions test/common/assertSnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,18 @@ function transformProjectRoot(replacement = '<project-root>') {
const winPath = replaceWindowsPaths(projectRoot);
// Handles URL encoded project root in file URL strings as well.
const urlEncoded = pathToFileURL(projectRoot).pathname;
// On Windows, paths are case-insensitive, so we need to use case-insensitive
// regex replacement to handle cases where the drive letter case differs.
const flags = common.isWindows ? 'gi' : 'g';
const urlEncodedRegex = new RegExp(RegExp.escape(urlEncoded), flags);
const projectRootRegex = new RegExp(RegExp.escape(projectRoot), flags);
const winPathRegex = new RegExp(RegExp.escape(winPath), flags);
return (str) => {
return str.replaceAll('\\\'', "'")
// Replace fileUrl first as `winPath` could be a substring of the fileUrl.
.replaceAll(urlEncoded, replacement)
.replaceAll(projectRoot, replacement)
.replaceAll(winPath, replacement);
.replaceAll(urlEncodedRegex, replacement)
.replaceAll(projectRootRegex, replacement)
.replaceAll(winPathRegex, replacement);
};
}

Expand Down
Loading
0