-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
reporter.spec.coffee
137 lines (99 loc) · 5.32 KB
/
reporter.spec.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#==============================================================================
# lib/reporter.js module
#==============================================================================
describe 'reporter', ->
EventEmitter = require('events').EventEmitter
File = require('../../lib/file_list').File
loadFile = require('mocks').loadFile
q = require 'q'
m = null
beforeEach ->
m = loadFile __dirname + '/../../lib/reporter.js'
#==============================================================================
# formatError() [PRIVATE]
#==============================================================================
describe 'formatError', ->
formatError = emitter = null
beforeEach ->
emitter = new EventEmitter
formatError = m.createErrorFormatter '', emitter
it 'should indent', ->
expect(formatError 'Something', '\t').to.equal '\tSomething\n'
it 'should handle empty message', ->
expect(formatError null).to.equal '\n'
it 'should remove domain from files', ->
expect(formatError 'file http://localhost:8080/base/usr/a.js and ' +
'http://127.0.0.1:8080/base/home/b.js').
to.be.equal 'file /usr/a.js and /home/b.js\n'
# TODO(vojta): enable once we serve source under urlRoot
it.skip 'should handle non default karma service folders', ->
formatError = m.createErrorFormatter '', '/_karma_/'
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'
it 'should remove shas', ->
ERROR = 'file ' +
'http://localhost:8080/base/usr/file.js?6e31cb249ee5b32d91f37ea516ca0f84bddc5aa9 ' +
'and ' +
'http://127.0.0.1:8080/absolute/home/file.js?6e31cb249ee5b32d91f37ea516ca0f84bddc5aa9'
expect(formatError ERROR).to.be.equal 'file /usr/file.js and /home/file.js\n'
it 'should indent all lines', ->
expect(formatError 'first\nsecond\nthird', '\t').to.equal '\tfirst\n\tsecond\n\tthird\n'
it 'should restore base paths', ->
formatError = m.createErrorFormatter '/some/base', emitter
expect(formatError 'at http://localhost:123/base/a.js?123').to.equal 'at /some/base/a.js\n'
it 'should restore absolute paths', ->
ERROR = 'at http://local:1233/absolute/usr/path.js?6e31cb249ee5b32d91f37ea516ca0f84bddc5aa9'
expect(formatError ERROR).to.equal 'at /usr/path.js\n'
it 'should preserve line numbers', ->
ERROR = 'at http://local:1233/absolute/usr/path.js?6e31cb249ee5b32d91f37ea516ca0f84bddc5aa9:2'
expect(formatError ERROR).to.equal 'at /usr/path.js:2\n'
describe 'source maps', ->
class MockSourceMapConsumer
constructor: (sourceMap) ->
@source = sourceMap.content.replace 'SOURCE MAP ', '/original/'
originalPositionFor: (position) ->
if position.line == 0
throw new TypeError('Line must be greater than or equal to 1, got 0')
source: @source
line: position.line + 2
column: position.column + 2
it 'should rewrite stack traces', (done) ->
formatError = m.createErrorFormatter '/some/base', emitter, MockSourceMapConsumer
servedFiles = [new File('/some/base/a.js'), new File('/some/base/b.js')]
servedFiles[0].sourceMap = {content: 'SOURCE MAP a.js'}
servedFiles[1].sourceMap = {content: 'SOURCE MAP b.js'}
emitter.emit 'file_list_modified', q(served: servedFiles)
scheduleNextTick ->
ERROR = 'at http://localhost:123/base/b.js:2:6'
expect(formatError ERROR).to.equal 'at /some/base/b.js:2:6 <- /original/b.js:4:8\n'
done()
it 'should fall back to non-source-map format if originalPositionFor throws', (done) ->
formatError = m.createErrorFormatter '/some/base', emitter, MockSourceMapConsumer
servedFiles = [new File('/some/base/a.js'), new File('/some/base/b.js')]
servedFiles[0].sourceMap = 'SOURCE MAP a.js'
servedFiles[1].sourceMap = 'SOURCE MAP b.js'
emitter.emit 'file_list_modified', q(served: servedFiles)
scheduleNextTick ->
ERROR = 'at http://localhost:123/base/b.js:0:0'
expect(formatError ERROR).to.equal 'at /some/base/b.js\n'
done()
describe 'Windows', ->
formatError = null
servedFiles = null
beforeEach ->
formatError = m.createErrorFormatter '/some/base', emitter, MockSourceMapConsumer
servedFiles = [new File('C:/a/b/c.js')]
servedFiles[0].sourceMap = {content: 'SOURCE MAP b.js'}
it 'should correct rewrite stack traces without sha', (done) ->
emitter.emit 'file_list_modified', q(served: servedFiles)
scheduleNextTick ->
ERROR = 'at http://localhost:123/absoluteC:/a/b/c.js:2:6'
expect(formatError ERROR).to.equal 'at C:/a/b/c.js:2:6 <- /original/b.js:4:8\n'
done()
it 'should correct rewrite stack traces with sha', (done) ->
emitter.emit 'file_list_modified', q(served: servedFiles)
scheduleNextTick ->
ERROR = 'at http://localhost:123/absoluteC:/a/b/c.js?da39a3ee5e6:2:6'
expect(formatError ERROR).to.equal 'at C:/a/b/c.js:2:6 <- /original/b.js:4:8\n'
done()