@@ -2,6 +2,7 @@ import {EventEmitter} from 'events'
2
2
import { loadFile } from 'mocks'
3
3
import path from 'path'
4
4
import _ from 'lodash'
5
+ import sinon from 'sinon'
5
6
6
7
import File from '../../lib/file'
7
8
@@ -15,10 +16,43 @@ describe('reporter', () => {
15
16
describe ( 'formatError' , ( ) => {
16
17
var emitter
17
18
var formatError = emitter = null
19
+ var sandbox
18
20
19
21
beforeEach ( ( ) => {
20
22
emitter = new EventEmitter ( )
21
- formatError = m . createErrorFormatter ( '' , emitter )
23
+ formatError = m . createErrorFormatter ( { basePath : '' } , emitter )
24
+ sandbox = sinon . sandbox . create ( )
25
+ } )
26
+
27
+ it ( 'should call config.formatError if defined' , ( ) => {
28
+ var spy = sandbox . spy ( )
29
+ formatError = m . createErrorFormatter ( { basePath : '' , formatError : spy } , emitter )
30
+ formatError ( )
31
+
32
+ expect ( spy ) . to . have . been . calledOnce
33
+ } )
34
+
35
+ it ( 'should not call config.formatError if not defined' , ( ) => {
36
+ var spy = sandbox . spy ( )
37
+ formatError ( )
38
+
39
+ expect ( spy ) . not . to . have . been . calledOnce
40
+ } )
41
+
42
+ it ( 'should pass the error message as the first config.formatError argument' , ( ) => {
43
+ var ERROR = 'foo bar'
44
+ var spy = sandbox . spy ( )
45
+ formatError = m . createErrorFormatter ( { basePath : '' , formatError : spy } , emitter )
46
+ formatError ( ERROR )
47
+
48
+ expect ( spy . firstCall . args [ 0 ] ) . to . equal ( ERROR )
49
+ } )
50
+
51
+ it ( 'should display the error returned by config.formatError' , ( ) => {
52
+ var formattedError = 'A new error'
53
+ formatError = m . createErrorFormatter ( { basePath : '' , formatError : ( ) => formattedError } , emitter )
54
+
55
+ expect ( formatError ( 'Something' , '\t' ) ) . to . equal ( formattedError + '\n' )
22
56
} )
23
57
24
58
it ( 'should indent' , ( ) => {
@@ -51,7 +85,7 @@ describe('reporter', () => {
51
85
52
86
// TODO(vojta): enable once we serve source under urlRoot
53
87
it . skip ( 'should handle non default karma service folders' , ( ) => {
54
- formatError = m . createErrorFormatter ( '' , '/_karma_/' )
88
+ formatError = m . createErrorFormatter ( { basePath : '' } , '/_karma_/' )
55
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' )
56
90
} )
57
91
@@ -65,7 +99,7 @@ describe('reporter', () => {
65
99
} )
66
100
67
101
it ( 'should restore base paths' , ( ) => {
68
- formatError = m . createErrorFormatter ( '/some/base' , emitter )
102
+ formatError = m . createErrorFormatter ( { basePath : '/some/base' } , emitter )
69
103
expect ( formatError ( 'at http://localhost:123/base/a.js?123' ) ) . to . equal ( 'at a.js\n' )
70
104
} )
71
105
@@ -121,7 +155,7 @@ describe('reporter', () => {
121
155
MockSourceMapConsumer . LEAST_UPPER_BOUND = 2
122
156
123
157
it ( 'should rewrite stack traces' , ( done ) => {
124
- formatError = m . createErrorFormatter ( '/some/base' , emitter , MockSourceMapConsumer )
158
+ formatError = m . createErrorFormatter ( { basePath : '/some/base' } , emitter , MockSourceMapConsumer )
125
159
var servedFiles = [ new File ( '/some/base/a.js' ) , new File ( '/some/base/b.js' ) ]
126
160
servedFiles [ 0 ] . sourceMap = { content : 'SOURCE MAP a.js' }
127
161
servedFiles [ 1 ] . sourceMap = { content : 'SOURCE MAP b.js' }
@@ -136,7 +170,7 @@ describe('reporter', () => {
136
170
} )
137
171
138
172
it ( 'should rewrite stack traces to the first column when no column is given' , ( done ) => {
139
- formatError = m . createErrorFormatter ( '/some/base' , emitter , MockSourceMapConsumer )
173
+ formatError = m . createErrorFormatter ( { basePath : '/some/base' } , emitter , MockSourceMapConsumer )
140
174
var servedFiles = [ new File ( '/some/base/a.js' ) , new File ( '/some/base/b.js' ) ]
141
175
servedFiles [ 0 ] . sourceMap = { content : 'SOURCE MAP a.js' }
142
176
servedFiles [ 1 ] . sourceMap = { content : 'SOURCE MAP b.js' }
@@ -151,7 +185,7 @@ describe('reporter', () => {
151
185
} )
152
186
153
187
it ( 'should rewrite relative url stack traces' , ( done ) => {
154
- formatError = m . createErrorFormatter ( '/some/base' , emitter , MockSourceMapConsumer )
188
+ formatError = m . createErrorFormatter ( { basePath : '/some/base' } , emitter , MockSourceMapConsumer )
155
189
var servedFiles = [ new File ( '/some/base/a.js' ) , new File ( '/some/base/b.js' ) ]
156
190
servedFiles [ 0 ] . sourceMap = { content : 'SOURCE MAP a.js' }
157
191
servedFiles [ 1 ] . sourceMap = { content : 'SOURCE MAP b.js' }
@@ -167,7 +201,7 @@ describe('reporter', () => {
167
201
168
202
it ( 'should resolve relative urls from source maps' , ( done ) => {
169
203
sourceMappingPath = 'original/' // Note: relative path.
170
- formatError = m . createErrorFormatter ( '/some/base' , emitter , MockSourceMapConsumer )
204
+ formatError = m . createErrorFormatter ( { basePath : '/some/base' } , emitter , MockSourceMapConsumer )
171
205
var servedFiles = [ new File ( '/some/base/path/a.js' ) ]
172
206
servedFiles [ 0 ] . sourceMap = { content : 'SOURCE MAP a.fancyjs' }
173
207
@@ -181,7 +215,7 @@ describe('reporter', () => {
181
215
} )
182
216
183
217
it ( 'should fall back to non-source-map format if originalPositionFor throws' , ( done ) => {
184
- formatError = m . createErrorFormatter ( '/some/base' , emitter , MockSourceMapConsumer )
218
+ formatError = m . createErrorFormatter ( { basePath : '/some/base' } , emitter , MockSourceMapConsumer )
185
219
var servedFiles = [ new File ( '/some/base/a.js' ) , new File ( '/some/base/b.js' ) ]
186
220
servedFiles [ 0 ] . sourceMap = { content : 'SOURCE MAP a.js' }
187
221
servedFiles [ 1 ] . sourceMap = { content : 'SOURCE MAP b.js' }
@@ -196,7 +230,7 @@ describe('reporter', () => {
196
230
} )
197
231
198
232
it ( 'should not try to use source maps when no line is given' , ( done ) => {
199
- formatError = m . createErrorFormatter ( '/some/base' , emitter , MockSourceMapConsumer )
233
+ formatError = m . createErrorFormatter ( { basePath : '/some/base' } , emitter , MockSourceMapConsumer )
200
234
var servedFiles = [ new File ( '/some/base/a.js' ) , new File ( '/some/base/b.js' ) ]
201
235
servedFiles [ 0 ] . sourceMap = { content : 'SOURCE MAP a.js' }
202
236
servedFiles [ 1 ] . sourceMap = { content : 'SOURCE MAP b.js' }
@@ -216,7 +250,7 @@ describe('reporter', () => {
216
250
var servedFiles = null
217
251
218
252
beforeEach ( ( ) => {
219
- formatError = m . createErrorFormatter ( '/some/base' , emitter , MockSourceMapConsumer )
253
+ formatError = m . createErrorFormatter ( { basePath : '/some/base' } , emitter , MockSourceMapConsumer )
220
254
servedFiles = [ new File ( 'C:/a/b/c.js' ) ]
221
255
servedFiles [ 0 ] . sourceMap = { content : 'SOURCE MAP b.js' }
222
256
} )
0 commit comments