Skip to content

Commit

Permalink
[Fix] stack trace path parsing on windows
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
Joris-van-der-Wel authored and ljharb committed Jan 7, 2024
1 parent 4640a91 commit 9cbae8a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/test.js
Expand Up @@ -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(
Expand Down

0 comments on commit 9cbae8a

Please sign in to comment.