karma-runner / karma-runner/karma

Stacktrace rewrite (sourceMap support) fails for absolute Windows paths

Open
#1,097 1 comment 0 reactions 0 assignees View on GitHub
help wanted type: backlog type: bug windows
Dominant language
JavaScript
Stars
12k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

The regex for attaching source locations in [lib/reporter.js#L25](https://github.com/karma-runner/karma/blob/master/lib/reporter.js#L25) fails to match absolute Windows path.

The problem is that the regular expression matches drive letters in path such as `C:/foo,js` as as the path name. This leads to the stack trace below not being rewritten.

```
Error: intentional
at http://localhost:9876/absoluteC:/foo.js?da39a3ee5e6b4b0d3255bfef95601890afd80709:17
```

We could make the used regular expression less restrictive by removing the `\\:` part from the path segment to fix the issue.

```
var URL_REGEXP = new RegExp('http:\\/\\/[^\\/]*\\/' +
'(base|absolute)' + // prefix
'([^\\?\\s\\]*)' + // path
'(\\?\\w*)?' + // sha
'(\\:(\\d+))?' + // line
'(\\:(\\d+))?' + // column
'', 'g');`
```

This however this breaks the existing test case.

An additional test case for [test/unit/reporter.spec.coffee](https://github.com/karma-runner/karma/blob/master/test/unit/reporter.spec.coffee) that must must pass on Windows systems could be the following:

```
it 'should rewrite absolute stack trace (Windows)', (done) ->

formatError = m.createErrorFormatter '/some/base', emitter, MockSourceMapConsumer
servedFiles = [new File('C:/b.js')]
servedFiles[0].sourceMap = 'SOURCE MAP b.js'

emitter.emit 'file_list_modified', q(served: servedFiles)

scheduleNextTick ->
ERROR = 'at http://localhost:123/base/C:/b.js:2:6'
expect(formatError ERROR).to.equal 'at /some/base/b.js:2:6 <- C:/original/b.js:4:8\n'
done()
```

Maybe I am mistaken but I believe a simple regex fix will not solve the issue across all platforms.

Give me the OK to rewrite the URL matching with some more sophisticated logic and I am happy to provide a pull request.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.