From 9cbae8a7e22567d30019e0cbc03c8597f03b4230 Mon Sep 17 00:00:00 2001 From: Joris van der Wel Date: Sun, 7 Jan 2024 17:50:12 +0100 Subject: [PATCH] [Fix] stack trace path parsing on windows Source files which are located in the current working directory, have a part of their path replaced by `path.sep + '$CWD'`. However, this causes the regular expression for stack trace lines to not match on windows. Example of a stack trace line, after replacement (`console.log(lineWithTokens)` in lib/test.js): ``` at Test.assert [as _assert] (\$CWD\example\my-test.js:483:11) ``` The part of the regexp that fails is `(?:\/|[a-zA-Z]:\\)`. I fixed this by allowing the path to start with a backslash. So instead of `\/`, the regexp uses `[/\\]`. This issue is already covered by existing test cases that are currently failing when they are ran on windows. For example: `.\node_modules\.bin\tap test/*.js` --- lib/test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/test.js b/lib/test.js index 78076cdb..04ba31a3 100644 --- a/lib/test.js +++ b/lib/test.js @@ -518,9 +518,9 @@ Test.prototype._assert = function assert(ok, opts) { Last part captures file path plus line no (and optional column no). - /((?:\/|[a-zA-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)\)?/ + /((?:[/\\]|[a-zA-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)\)?/ */ - var re = /^(?:[^\s]*\s*\bat\s+)(?:(.*)\s+\()?((?:\/|[a-zA-Z]:\\)[^:)]+:(\d+)(?::(\d+))?)\)?$/; + var re = /^(?:[^\s]*\s*\bat\s+)(?:(.*)\s+\()?((?:[/\\]|[a-zA-Z]:\\)[^:)]+:(\d+)(?::(\d+))?)\)?$/; // first tokenize the PWD, then tokenize tape var lineWithTokens = $replace( $replace(