diff --git a/lib/reporter.js b/lib/reporter.js index 546571db6..5caedae04 100644 --- a/lib/reporter.js +++ b/lib/reporter.js @@ -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) { @@ -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 diff --git a/test/unit/reporter.spec.js b/test/unit/reporter.spec.js index cb8dd15c3..230817bd3 100644 --- a/test/unit/reporter.spec.js +++ b/test/unit/reporter.spec.js @@ -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')