Skip to content

Commit

Permalink
Merge pull request #2899 from outsideris/fix-bad-url-in-stacktrace
Browse files Browse the repository at this point in the history
fix(reporter): show file path correctly when urlRoot specified
  • Loading branch information
dignifiedquire committed Dec 5, 2017
2 parents 78ad12f + 34dc7d3 commit f64e1e0
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
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
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

0 comments on commit f64e1e0

Please sign in to comment.