@@ -44,7 +44,6 @@ describe('reporter', () => {
44
44
let createCoverageSummaryStub = null
45
45
let createCoverageMapStub = null
46
46
let createContextStub = null
47
- let packageSummaryStub = null
48
47
let getDefaultWatermarkStub = null
49
48
let sourceMapStoreGetStub = null
50
49
let globalCoverageMapGetStub = null
@@ -82,19 +81,14 @@ describe('reporter', () => {
82
81
functions : [ 50 , 80 ] ,
83
82
lines : [ 50 , 80 ]
84
83
}
85
- mockPackageSummary = {
86
- visit : sinon . stub ( )
87
- }
88
84
createContextStub = sinon . stub ( istanbulLibReport , 'createContext' )
89
- packageSummaryStub = sinon . stub ( istanbulLibReport . summarizers , 'pkg' )
90
- packageSummaryStub . returns ( mockPackageSummary )
91
85
getDefaultWatermarkStub = sinon . stub ( istanbulLibReport , 'getDefaultWatermarks' )
92
86
getDefaultWatermarkStub . returns ( mockDefaultWatermarks )
93
87
94
88
mockSourceMapStore = {
95
89
transformCoverage : sinon . stub ( )
96
90
}
97
- mockSourceMapStore . transformCoverage . returns ( { map : mockCoverageMap } )
91
+ mockSourceMapStore . transformCoverage . resolves ( mockCoverageMap )
98
92
sourceMapStoreGetStub = sinon . stub ( globalSourceMapStore , 'get' )
99
93
sourceMapStoreGetStub . returns ( mockSourceMapStore )
100
94
@@ -103,7 +97,9 @@ describe('reporter', () => {
103
97
globalCoverageMapGetStub . returns ( mockGlobalCoverageMap )
104
98
sinon . stub ( globalCoverageMap , 'add' )
105
99
100
+ mockPackageSummary = { execute : sinon . stub ( ) }
106
101
reportCreateStub = sinon . stub ( reports , 'create' )
102
+ reportCreateStub . returns ( mockPackageSummary )
107
103
108
104
m = loadFile ( path . join ( __dirname , '/../lib/reporter.js' ) , mocks )
109
105
} )
@@ -162,22 +158,22 @@ describe('reporter', () => {
162
158
expect ( mockCoverageMap . merge ) . not . to . have . been . called
163
159
} )
164
160
165
- it ( 'should make reports' , ( ) => {
166
- reporter . onRunComplete ( browsers )
161
+ it ( 'should make reports' , async ( ) => {
162
+ await reporter . onRunComplete ( browsers )
167
163
expect ( mkdirIfNotExistsStub ) . to . have . been . calledTwice
168
164
const dir = rootConfig . coverageReporter . dir
169
165
expect ( mkdirIfNotExistsStub . getCall ( 0 ) . args [ 0 ] ) . to . deep . equal ( resolve ( '/base' , dir , fakeChrome . name ) )
170
166
expect ( mkdirIfNotExistsStub . getCall ( 1 ) . args [ 0 ] ) . to . deep . equal ( resolve ( '/base' , dir , fakeOpera . name ) )
171
167
mkdirIfNotExistsStub . getCall ( 0 ) . args [ 1 ] ( )
172
168
expect ( reportCreateStub ) . to . have . been . called
173
- expect ( mockPackageSummary . visit ) . to . have . been . called
169
+ expect ( mockPackageSummary . execute ) . to . have . been . called
174
170
const createArgs = reportCreateStub . getCall ( 0 ) . args
175
171
expect ( createArgs [ 0 ] ) . to . be . equal ( 'html' )
176
172
expect ( createArgs [ 1 ] . browser ) . to . be . equal ( fakeChrome )
177
173
expect ( createArgs [ 1 ] . emitter ) . to . be . equal ( emitter )
178
174
} )
179
175
180
- it ( 'should support a string for the subdir option' , ( ) => {
176
+ it ( 'should support a string for the subdir option' , async ( ) => {
181
177
const customConfig = helper . merge ( { } , rootConfig , {
182
178
coverageReporter : {
183
179
subdir : 'test'
@@ -188,18 +184,18 @@ describe('reporter', () => {
188
184
reporter . onRunStart ( )
189
185
browsers . forEach ( b => reporter . onBrowserStart ( b ) )
190
186
191
- reporter . onRunComplete ( browsers )
187
+ await reporter . onRunComplete ( browsers )
192
188
expect ( mkdirIfNotExistsStub ) . to . have . been . calledTwice
193
189
const dir = customConfig . coverageReporter . dir
194
190
const subdir = customConfig . coverageReporter . subdir
195
191
expect ( mkdirIfNotExistsStub . getCall ( 0 ) . args [ 0 ] ) . to . deep . equal ( resolve ( '/base' , dir , subdir ) )
196
192
expect ( mkdirIfNotExistsStub . getCall ( 1 ) . args [ 0 ] ) . to . deep . equal ( resolve ( '/base' , dir , subdir ) )
197
193
mkdirIfNotExistsStub . getCall ( 0 ) . args [ 1 ] ( )
198
194
expect ( reportCreateStub ) . to . have . been . called
199
- expect ( mockPackageSummary . visit ) . to . have . been . called
195
+ expect ( mockPackageSummary . execute ) . to . have . been . called
200
196
} )
201
197
202
- it ( 'should support a function for the subdir option' , ( ) => {
198
+ it ( 'should support a function for the subdir option' , async ( ) => {
203
199
const customConfig = helper . merge ( { } , rootConfig , {
204
200
coverageReporter : {
205
201
subdir : ( browserName ) => browserName . toLowerCase ( ) . split ( / [ / - ] / ) [ 0 ]
@@ -210,17 +206,17 @@ describe('reporter', () => {
210
206
reporter . onRunStart ( )
211
207
browsers . forEach ( b => reporter . onBrowserStart ( b ) )
212
208
213
- reporter . onRunComplete ( browsers )
209
+ await reporter . onRunComplete ( browsers )
214
210
expect ( mkdirIfNotExistsStub ) . to . have . been . calledTwice
215
211
const dir = customConfig . coverageReporter . dir
216
212
expect ( mkdirIfNotExistsStub . getCall ( 0 ) . args [ 0 ] ) . to . deep . equal ( resolve ( '/base' , dir , 'chrome' ) )
217
213
expect ( mkdirIfNotExistsStub . getCall ( 1 ) . args [ 0 ] ) . to . deep . equal ( resolve ( '/base' , dir , 'opera' ) )
218
214
mkdirIfNotExistsStub . getCall ( 0 ) . args [ 1 ] ( )
219
215
expect ( reportCreateStub ) . to . have . been . called
220
- expect ( mockPackageSummary . visit ) . to . have . been . called
216
+ expect ( mockPackageSummary . execute ) . to . have . been . called
221
217
} )
222
218
223
- it ( 'should support a specific dir and subdir per reporter' , ( ) => {
219
+ it ( 'should support a specific dir and subdir per reporter' , async ( ) => {
224
220
const customConfig = helper . merge ( { } , rootConfig , {
225
221
coverageReporter : {
226
222
dir : 'useless' ,
@@ -242,18 +238,18 @@ describe('reporter', () => {
242
238
reporter . onRunStart ( )
243
239
browsers . forEach ( b => reporter . onBrowserStart ( b ) )
244
240
245
- reporter . onRunComplete ( browsers )
241
+ await reporter . onRunComplete ( browsers )
246
242
expect ( mkdirIfNotExistsStub . callCount ) . to . equal ( 4 )
247
243
expect ( mkdirIfNotExistsStub . getCall ( 0 ) . args [ 0 ] ) . to . deep . equal ( resolve ( '/base' , 'reporter1' , 'chrome' ) )
248
244
expect ( mkdirIfNotExistsStub . getCall ( 1 ) . args [ 0 ] ) . to . deep . equal ( resolve ( '/base' , 'reporter1' , 'opera' ) )
249
245
expect ( mkdirIfNotExistsStub . getCall ( 2 ) . args [ 0 ] ) . to . deep . equal ( resolve ( '/base' , 'reporter2' , 'CHROME' ) )
250
246
expect ( mkdirIfNotExistsStub . getCall ( 3 ) . args [ 0 ] ) . to . deep . equal ( resolve ( '/base' , 'reporter2' , 'OPERA' ) )
251
247
mkdirIfNotExistsStub . getCall ( 0 ) . args [ 1 ] ( )
252
248
expect ( reportCreateStub ) . to . have . been . called
253
- expect ( mockPackageSummary . visit ) . to . have . been . called
249
+ expect ( mockPackageSummary . execute ) . to . have . been . called
254
250
} )
255
251
256
- it ( 'should fallback to the default dir/subdir if not provided' , ( ) => {
252
+ it ( 'should fallback to the default dir/subdir if not provided' , async ( ) => {
257
253
const customConfig = helper . merge ( { } , rootConfig , {
258
254
coverageReporter : {
259
255
dir : 'defaultdir' ,
@@ -273,48 +269,48 @@ describe('reporter', () => {
273
269
reporter . onRunStart ( )
274
270
browsers . forEach ( b => reporter . onBrowserStart ( b ) )
275
271
276
- reporter . onRunComplete ( browsers )
272
+ await reporter . onRunComplete ( browsers )
277
273
expect ( mkdirIfNotExistsStub . callCount ) . to . equal ( 4 )
278
274
expect ( mkdirIfNotExistsStub . getCall ( 0 ) . args [ 0 ] ) . to . deep . equal ( resolve ( '/base' , 'reporter1' , 'defaultsubdir' ) )
279
275
expect ( mkdirIfNotExistsStub . getCall ( 1 ) . args [ 0 ] ) . to . deep . equal ( resolve ( '/base' , 'reporter1' , 'defaultsubdir' ) )
280
276
expect ( mkdirIfNotExistsStub . getCall ( 2 ) . args [ 0 ] ) . to . deep . equal ( resolve ( '/base' , 'defaultdir' , 'CHROME' ) )
281
277
expect ( mkdirIfNotExistsStub . getCall ( 3 ) . args [ 0 ] ) . to . deep . equal ( resolve ( '/base' , 'defaultdir' , 'OPERA' ) )
282
278
mkdirIfNotExistsStub . getCall ( 0 ) . args [ 1 ] ( )
283
279
expect ( reportCreateStub ) . to . have . been . called
284
- expect ( mockPackageSummary . visit ) . to . have . been . called
280
+ expect ( mockPackageSummary . execute ) . to . have . been . called
285
281
} )
286
282
287
- it ( 'should not create directory if reporting text* to console' , ( ) => {
283
+ it ( 'should not create directory if reporting text* to console' , async ( ) => {
288
284
const run = ( ) => {
289
285
reporter = new m . CoverageReporter ( rootConfig , mockHelper , mockLogger )
290
286
reporter . onRunStart ( )
291
287
browsers . forEach ( b => reporter . onBrowserStart ( b ) )
292
- reporter . onRunComplete ( browsers )
288
+ return reporter . onRunComplete ( browsers )
293
289
}
294
290
295
291
rootConfig . coverageReporter . reporters = [
296
292
{ type : 'text' } ,
297
293
{ type : 'text-summary' }
298
294
]
299
- run ( )
295
+ await run ( )
300
296
expect ( mkdirIfNotExistsStub ) . not . to . have . been . called
301
297
} )
302
298
303
- it ( 'should create directory if reporting text* to file' , ( ) => {
299
+ it ( 'should create directory if reporting text* to file' , async ( ) => {
304
300
const run = ( ) => {
305
301
reporter = new m . CoverageReporter ( rootConfig , mockHelper , mockLogger )
306
302
reporter . onRunStart ( )
307
303
browsers . forEach ( b => reporter . onBrowserStart ( b ) )
308
- reporter . onRunComplete ( browsers )
304
+ return reporter . onRunComplete ( browsers )
309
305
}
310
306
311
307
rootConfig . coverageReporter . reporters = [ { type : 'text' , file : 'file' } ]
312
- run ( )
308
+ await run ( )
313
309
expect ( mkdirIfNotExistsStub ) . to . have . been . calledTwice
314
310
315
311
mkdirIfNotExistsStub . resetHistory ( )
316
312
rootConfig . coverageReporter . reporters = [ { type : 'text-summary' , file : 'file' } ]
317
- run ( )
313
+ await run ( )
318
314
expect ( mkdirIfNotExistsStub ) . to . have . been . calledTwice
319
315
} )
320
316
@@ -370,7 +366,7 @@ describe('reporter', () => {
370
366
expect ( globalCoverageMapGetStub ) . not . to . have . been . called
371
367
} )
372
368
373
- it ( 'should pass watermarks to istanbul' , ( ) => {
369
+ it ( 'should pass watermarks to istanbul' , async ( ) => {
374
370
const watermarks = {
375
371
statements : [ 10 , 20 ] ,
376
372
branches : [ 30 , 40 ] ,
@@ -395,15 +391,15 @@ describe('reporter', () => {
395
391
reporter = new m . CoverageReporter ( customConfig , mockHelper , mockLogger )
396
392
reporter . onRunStart ( )
397
393
browsers . forEach ( b => reporter . onBrowserStart ( b ) )
398
- reporter . onRunComplete ( browsers )
394
+ await reporter . onRunComplete ( browsers )
399
395
400
396
expect ( createContextStub ) . to . have . been . called
401
397
expect ( reportCreateStub ) . to . have . been . called
402
398
const options = reportCreateStub . getCall ( 0 )
403
399
expect ( options . args [ 1 ] . watermarks ) . to . deep . equal ( watermarks )
404
400
} )
405
401
406
- it ( 'should merge with istanbul default watermarks' , ( ) => {
402
+ it ( 'should merge with istanbul default watermarks' , async ( ) => {
407
403
const watermarks = {
408
404
statements : [ 10 , 20 ] ,
409
405
lines : [ 70 , 80 ]
@@ -426,7 +422,7 @@ describe('reporter', () => {
426
422
reporter = new m . CoverageReporter ( customConfig , mockHelper , mockLogger )
427
423
reporter . onRunStart ( )
428
424
browsers . forEach ( b => reporter . onBrowserStart ( b ) )
429
- reporter . onRunComplete ( browsers )
425
+ await reporter . onRunComplete ( browsers )
430
426
431
427
expect ( createContextStub ) . to . have . been . called
432
428
expect ( reportCreateStub ) . to . have . been . called
@@ -437,7 +433,7 @@ describe('reporter', () => {
437
433
expect ( options . args [ 1 ] . watermarks . lines ) . to . deep . equal ( watermarks . lines )
438
434
} )
439
435
440
- it ( 'should log errors on low coverage and fail the build' , ( ) => {
436
+ it ( 'should log errors on low coverage and fail the build' , async ( ) => {
441
437
const customConfig = helper . merge ( { } , rootConfig , {
442
438
coverageReporter : {
443
439
check : {
@@ -472,13 +468,13 @@ describe('reporter', () => {
472
468
reporter = new m . CoverageReporter ( customConfig , mockHelper , customLogger )
473
469
reporter . onRunStart ( )
474
470
browsers . forEach ( b => reporter . onBrowserStart ( b ) )
475
- reporter . onRunComplete ( browsers , results )
471
+ await reporter . onRunComplete ( browsers , results )
476
472
477
473
expect ( spy1 ) . to . have . been . called
478
474
expect ( results . exitCode ) . to . not . equal ( 0 )
479
475
} )
480
476
481
- it ( 'should not log errors on sufficient coverage and not fail the build' , ( ) => {
477
+ it ( 'should not log errors on sufficient coverage and not fail the build' , async ( ) => {
482
478
const customConfig = helper . merge ( { } , rootConfig , {
483
479
coverageReporter : {
484
480
check : {
@@ -513,7 +509,7 @@ describe('reporter', () => {
513
509
reporter = new m . CoverageReporter ( customConfig , mockHelper , customLogger )
514
510
reporter . onRunStart ( )
515
511
browsers . forEach ( b => reporter . onBrowserStart ( b ) )
516
- reporter . onRunComplete ( browsers , results )
512
+ await reporter . onRunComplete ( browsers , results )
517
513
518
514
expect ( spy1 ) . to . not . have . been . called
519
515
0 commit comments