Skip to content

Commit

Permalink
fix(reporter): show file path correctly when urlRoot specified
Browse files Browse the repository at this point in the history
Handle urlRoot in paths if rulRoot specified

Closes #2897
  • Loading branch information
outsideris committed Dec 3, 2017
1 parent b53929a commit 34dc7d3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var baseReporterDecoratorFactory = require('./reporters/base').decoratorFactory

var createErrorFormatter = function (config, emitter, SourceMapConsumer) {
var basePath = config.basePath
var urlRoot = config.urlRoot || ''
var lastServedFiles = []

emitter.on('file_list_modified', function (files) {
Expand All @@ -26,6 +27,7 @@ var createErrorFormatter = function (config, emitter, SourceMapConsumer) {

var URL_REGEXP = new RegExp('(?:https?:\\/\\/' +
config.hostname + '(?:\\:' + config.port + ')?' + ')?\\/?' +
urlRoot + '\\/?' +
'(base/|absolute)' + // prefix, including slash for base/ to create relative paths.
'((?:[A-z]\\:)?[^\\?\\s\\:]*)' + // path
'(\\?\\w*)?' + // sha
Expand Down
5 changes: 5 additions & 0 deletions test/unit/reporter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ describe('reporter', () => {
expect(formatError('at http://localhost:123/base/a.js?123')).to.equal('at a.js\n')
})

it('should restore urlRoot paths', () => {
formatError = m.createErrorFormatter({ urlRoot: '/__karma__', basePath: '/some/base', hostname: 'localhost', port: 123 }, emitter)
expect(formatError('at http://localhost:123/__karma__/base/sub/a.js?123')).to.equal('at sub/a.js\n')
})

it('should restore absolute paths', () => {
var ERROR = 'at http://localhost:8080/absolute/usr/path.js?6e31cb249ee5b32d91f37ea516ca0f84bddc5aa9'
expect(formatError(ERROR)).to.equal('at /usr/path.js\n')
Expand Down

1 comment on commit 34dc7d3

@doberkofler
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least in my environment this commit prevents Karma 2.0 from showing the original source line and column when using source maps. Because of the new RegEx component urlRoot + '\\/?', the url now must start with /base and because Karma automatically normalizes the urlRoot configuration option, it is also not possible to set it to an empty string. I submitted the following issue

Please sign in to comment.