Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7643bc8

Browse filesBrowse files
mcollinaaduh95
authored andcommitted
test: fix case-insensitive path matching on Windows
On Windows, file paths are case-insensitive but string comparison is case-sensitive. When the drive letter case differs between the computed project root and the actual output (e.g., 'C:/' vs 'c:/'), the path replacement in transformProjectRoot() would fail. This fix uses case-insensitive regex replacement on Windows to ensure paths are correctly normalized in snapshot tests regardless of drive letter casing. Refs: nodejs/reliability#1453 PR-URL: #61682 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
1 parent a2843f8 commit 7643bc8
Copy full SHA for 7643bc8

1 file changed

+9-3Lines changed: 9 additions & 3 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/common/assertSnapshot.js‎

Copy file name to clipboardExpand all lines: test/common/assertSnapshot.js
+9-3Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,18 @@ function transformProjectRoot(replacement = '<project-root>') {
6464
const winPath = replaceWindowsPaths(projectRoot);
6565
// Handles URL encoded project root in file URL strings as well.
6666
const urlEncoded = pathToFileURL(projectRoot).pathname;
67+
// On Windows, paths are case-insensitive, so we need to use case-insensitive
68+
// regex replacement to handle cases where the drive letter case differs.
69+
const flags = common.isWindows ? 'gi' : 'g';
70+
const urlEncodedRegex = new RegExp(RegExp.escape(urlEncoded), flags);
71+
const projectRootRegex = new RegExp(RegExp.escape(projectRoot), flags);
72+
const winPathRegex = new RegExp(RegExp.escape(winPath), flags);
6773
return (str) => {
6874
return str.replaceAll('\\\'', "'")
6975
// Replace fileUrl first as `winPath` could be a substring of the fileUrl.
70-
.replaceAll(urlEncoded, replacement)
71-
.replaceAll(projectRoot, replacement)
72-
.replaceAll(winPath, replacement);
76+
.replaceAll(urlEncodedRegex, replacement)
77+
.replaceAll(projectRootRegex, replacement)
78+
.replaceAll(winPathRegex, replacement);
7379
};
7480
}
7581

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.