From 82c37dd743ff06a7f5268927669a1ed0080211b9 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 31 Jul 2023 23:54:28 +0200 Subject: [PATCH] test: fix snapshot tests when cwd contains spaces or backslashes Both are valid characters for file names on non-Windows systems. PR-URL: https://github.com/nodejs/node/pull/48959 Reviewed-By: Moshe Atlow Reviewed-By: Luigi Pinca --- test/common/assertSnapshot.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/common/assertSnapshot.js b/test/common/assertSnapshot.js index c403751ac3ef5e..10a5941b41ff37 100644 --- a/test/common/assertSnapshot.js +++ b/test/common/assertSnapshot.js @@ -5,7 +5,7 @@ const test = require('node:test'); const fs = require('node:fs/promises'); const assert = require('node:assert/strict'); -const stackFramesRegexp = /(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\[\d+m)?(\n|$)/g; +const stackFramesRegexp = /(?<=\n)(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\[\d+m)?(\n|$)/g; const windowNewlineRegexp = /\r/g; function replaceStackTrace(str, replacement = '$1*$7$8\n') { @@ -17,7 +17,7 @@ function replaceWindowsLineEndings(str) { } function replaceWindowsPaths(str) { - return str.replaceAll(path.win32.sep, path.posix.sep); + return common.isWindows ? str.replaceAll(path.win32.sep, path.posix.sep) : str; } function transform(...args) {