Skip to content

Commit 9cbae8a

Browse files
Joris-van-der-Welljharb
authored andcommitted
[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`
1 parent 4640a91 commit 9cbae8a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -518,9 +518,9 @@ Test.prototype._assert = function assert(ok, opts) {
518518
Last part captures file path plus line no (and optional
519519
column no).
520520
521-
/((?:\/|[a-zA-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)\)?/
521+
/((?:[/\\]|[a-zA-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)\)?/
522522
*/
523-
var re = /^(?:[^\s]*\s*\bat\s+)(?:(.*)\s+\()?((?:\/|[a-zA-Z]:\\)[^:)]+:(\d+)(?::(\d+))?)\)?$/;
523+
var re = /^(?:[^\s]*\s*\bat\s+)(?:(.*)\s+\()?((?:[/\\]|[a-zA-Z]:\\)[^:)]+:(\d+)(?::(\d+))?)\)?$/;
524524
// first tokenize the PWD, then tokenize tape
525525
var lineWithTokens = $replace(
526526
$replace(

0 commit comments

Comments
 (0)