Skip to content

Commit fbbeccf

Browse files
wesleychodignifiedquire
authored andcommitted
fix(reporter): strip only hostname/port
Strip only specified hostname & port from result Fixes #2209
1 parent 3a618b3 commit fbbeccf

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

lib/reporter.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ var createErrorFormatter = function (config, emitter, SourceMapConsumer) {
2525
return null
2626
}
2727

28-
var URL_REGEXP = new RegExp('(?:https?:\\/\\/[^\\/\\s]*)?\\/?' +
28+
var URL_REGEXP = new RegExp('(?:https?:\\/\\/' +
29+
config.hostname + '(?:\\:' + config.port + ')?' + ')?\\/?' +
2930
'(base/|absolute)' + // prefix, including slash for base/ to create relative paths.
3031
'((?:[A-z]\\:)?[^\\?\\s\\:]*)' + // path
3132
'(\\?\\w*)?' + // sha

test/unit/reporter.spec.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('reporter', () => {
2020

2121
beforeEach(() => {
2222
emitter = new EventEmitter()
23-
formatError = m.createErrorFormatter({ basePath: '' }, emitter)
23+
formatError = m.createErrorFormatter({ basePath: '', hostname: 'localhost', port: 8080 }, emitter)
2424
sandbox = sinon.sandbox.create()
2525
})
2626

@@ -79,37 +79,37 @@ describe('reporter', () => {
7979
)
8080
})
8181

82-
it('should remove domain from files', () => {
83-
expect(formatError('file http://localhost:8080/base/usr/a.js and http://127.0.0.1:8080/absolute/home/b.js')).to.be.equal('file usr/a.js and /home/b.js\n')
82+
it('should remove specified hostname from files', () => {
83+
expect(formatError('file http://localhost:8080/base/usr/a.js and http://127.0.0.1:8080/absolute/home/b.js')).to.be.equal('file usr/a.js and http://127.0.0.1:8080/home/b.js\n')
8484
})
8585

8686
// TODO(vojta): enable once we serve source under urlRoot
8787
it.skip('should handle non default karma service folders', () => {
8888
formatError = m.createErrorFormatter({ basePath: '' }, '/_karma_/')
89-
expect(formatError('file http://localhost:8080/_karma_/base/usr/a.js and http://127.0.0.1:8080/_karma_/base/home/b.js')).to.be.equal('file usr/a.js and home/b.js\n')
89+
expect(formatError('file http://localhost:8080/_karma_/base/usr/a.js and http://localhost:8080/_karma_/base/home/b.js')).to.be.equal('file usr/a.js and home/b.js\n')
9090
})
9191

9292
it('should remove shas', () => {
9393
var ERROR = 'file http://localhost:8080/base/usr/file.js?6e31cb249ee5b32d91f37ea516ca0f84bddc5aa9 and http://127.0.0.1:8080/absolute/home/file.js?6e31cb249ee5b32d91f37ea516ca0f84bddc5aa9'
94-
expect(formatError(ERROR)).to.be.equal('file usr/file.js and /home/file.js\n')
94+
expect(formatError(ERROR)).to.be.equal('file usr/file.js and http://127.0.0.1:8080/home/file.js\n')
9595
})
9696

9797
it('should indent all lines', () => {
9898
expect(formatError('first\nsecond\nthird', '\t')).to.equal('\tfirst\n\tsecond\n\tthird\n')
9999
})
100100

101101
it('should restore base paths', () => {
102-
formatError = m.createErrorFormatter({ basePath: '/some/base' }, emitter)
102+
formatError = m.createErrorFormatter({ basePath: '/some/base', hostname: 'localhost', port: 123 }, emitter)
103103
expect(formatError('at http://localhost:123/base/a.js?123')).to.equal('at a.js\n')
104104
})
105105

106106
it('should restore absolute paths', () => {
107-
var ERROR = 'at http://local:1233/absolute/usr/path.js?6e31cb249ee5b32d91f37ea516ca0f84bddc5aa9'
107+
var ERROR = 'at http://localhost:8080/absolute/usr/path.js?6e31cb249ee5b32d91f37ea516ca0f84bddc5aa9'
108108
expect(formatError(ERROR)).to.equal('at /usr/path.js\n')
109109
})
110110

111111
it('should preserve line numbers', () => {
112-
var ERROR = 'at http://local:1233/absolute/usr/path.js?6e31cb249ee5b32d91f37ea516ca0f84bddc5aa9:2'
112+
var ERROR = 'at http://localhost:8080/absolute/usr/path.js?6e31cb249ee5b32d91f37ea516ca0f84bddc5aa9:2'
113113
expect(formatError(ERROR)).to.equal('at /usr/path.js:2\n')
114114
})
115115

@@ -155,7 +155,7 @@ describe('reporter', () => {
155155
MockSourceMapConsumer.LEAST_UPPER_BOUND = 2
156156

157157
it('should rewrite stack traces', (done) => {
158-
formatError = m.createErrorFormatter({ basePath: '/some/base' }, emitter, MockSourceMapConsumer)
158+
formatError = m.createErrorFormatter({ basePath: '/some/base', hostname: 'localhost', port: 123 }, emitter, MockSourceMapConsumer)
159159
var servedFiles = [new File('/some/base/a.js'), new File('/some/base/b.js')]
160160
servedFiles[0].sourceMap = {content: 'SOURCE MAP a.js'}
161161
servedFiles[1].sourceMap = {content: 'SOURCE MAP b.js'}
@@ -170,7 +170,7 @@ describe('reporter', () => {
170170
})
171171

172172
it('should rewrite stack traces to the first column when no column is given', (done) => {
173-
formatError = m.createErrorFormatter({ basePath: '/some/base' }, emitter, MockSourceMapConsumer)
173+
formatError = m.createErrorFormatter({ basePath: '/some/base', hostname: 'localhost', port: 123 }, emitter, MockSourceMapConsumer)
174174
var servedFiles = [new File('/some/base/a.js'), new File('/some/base/b.js')]
175175
servedFiles[0].sourceMap = {content: 'SOURCE MAP a.js'}
176176
servedFiles[1].sourceMap = {content: 'SOURCE MAP b.js'}
@@ -185,7 +185,7 @@ describe('reporter', () => {
185185
})
186186

187187
it('should rewrite relative url stack traces', (done) => {
188-
formatError = m.createErrorFormatter({ basePath: '/some/base' }, emitter, MockSourceMapConsumer)
188+
formatError = m.createErrorFormatter({ basePath: '/some/base', hostname: 'localhost', port: 123 }, emitter, MockSourceMapConsumer)
189189
var servedFiles = [new File('/some/base/a.js'), new File('/some/base/b.js')]
190190
servedFiles[0].sourceMap = {content: 'SOURCE MAP a.js'}
191191
servedFiles[1].sourceMap = {content: 'SOURCE MAP b.js'}
@@ -215,7 +215,7 @@ describe('reporter', () => {
215215
})
216216

217217
it('should fall back to non-source-map format if originalPositionFor throws', (done) => {
218-
formatError = m.createErrorFormatter({ basePath: '/some/base' }, emitter, MockSourceMapConsumer)
218+
formatError = m.createErrorFormatter({ basePath: '/some/base', hostname: 'localhost', port: 123 }, emitter, MockSourceMapConsumer)
219219
var servedFiles = [new File('/some/base/a.js'), new File('/some/base/b.js')]
220220
servedFiles[0].sourceMap = {content: 'SOURCE MAP a.js'}
221221
servedFiles[1].sourceMap = {content: 'SOURCE MAP b.js'}
@@ -230,7 +230,7 @@ describe('reporter', () => {
230230
})
231231

232232
it('should not try to use source maps when no line is given', (done) => {
233-
formatError = m.createErrorFormatter({ basePath: '/some/base' }, emitter, MockSourceMapConsumer)
233+
formatError = m.createErrorFormatter({ basePath: '/some/base', hostname: 'localhost', port: 123 }, emitter, MockSourceMapConsumer)
234234
var servedFiles = [new File('/some/base/a.js'), new File('/some/base/b.js')]
235235
servedFiles[0].sourceMap = {content: 'SOURCE MAP a.js'}
236236
servedFiles[1].sourceMap = {content: 'SOURCE MAP b.js'}
@@ -246,7 +246,7 @@ describe('reporter', () => {
246246
})
247247

248248
it('should not try to match domains with spaces', (done) => {
249-
formatError = m.createErrorFormatter({ basePath: '/some/base' }, emitter, MockSourceMapConsumer)
249+
formatError = m.createErrorFormatter({ basePath: '/some/base', hostname: 'localhost', port: 9876 }, emitter, MockSourceMapConsumer)
250250
var servedFiles = [new File('/some/base/a.js'), new File('/some/base/b.js')]
251251
servedFiles[0].sourceMap = {content: 'SOURCE MAP a.js'}
252252
servedFiles[1].sourceMap = {content: 'SOURCE MAP b.js'}
@@ -265,7 +265,7 @@ describe('reporter', () => {
265265
var servedFiles = null
266266

267267
beforeEach(() => {
268-
formatError = m.createErrorFormatter({ basePath: '/some/base' }, emitter, MockSourceMapConsumer)
268+
formatError = m.createErrorFormatter({ basePath: '/some/base', hostname: 'localhost', port: 123 }, emitter, MockSourceMapConsumer)
269269
servedFiles = [new File('C:/a/b/c.js')]
270270
servedFiles[0].sourceMap = {content: 'SOURCE MAP b.js'}
271271
})

0 commit comments

Comments
 (0)