From 08d1976758a8bc9be325be642f9d089c8c7dd58b Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 4 Feb 2026 17:21:06 +0100 Subject: [PATCH] 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: https://github.com/nodejs/reliability/issues/1453 --- test/common/assertSnapshot.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/common/assertSnapshot.js b/test/common/assertSnapshot.js index db3fdde31bec39..24eb60e913a9ce 100644 --- a/test/common/assertSnapshot.js +++ b/test/common/assertSnapshot.js @@ -64,12 +64,18 @@ function transformProjectRoot(replacement = '') { 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); }; }