@@ -174,17 +174,20 @@ var CoverageReporter = function (rootConfig, helper, logger, emitter) {
174
174
return coverageFailed
175
175
}
176
176
177
- // Generate the output directory from the `coverageReporter.dir` and
177
+ // Generate the output path from the `coverageReporter.dir` and
178
178
// `coverageReporter.subdir` options.
179
- function generateOutputDir ( browserName , dir , subdir ) {
180
- dir = dir || 'coverage'
181
- subdir = subdir || browserName
182
-
183
- if ( typeof subdir === 'function' ) {
179
+ function generateOutputPath ( basePath , browserName , dir = 'coverage' , subdir ) {
180
+ if ( subdir && typeof subdir === 'function' ) {
184
181
subdir = subdir ( browserName )
185
182
}
183
+ if ( browserName ) {
184
+ browserName = browserName . replace ( ':' , '' )
185
+ }
186
+
187
+ let outPutPath = path . join ( dir , subdir || browserName )
188
+ outPutPath = path . resolve ( basePath , outPutPath )
186
189
187
- return path . join ( dir , subdir )
190
+ return helper . normalizeWinPath ( outPutPath )
188
191
}
189
192
190
193
this . onRunStart = function ( browsers ) {
@@ -224,60 +227,54 @@ var CoverageReporter = function (rootConfig, helper, logger, emitter) {
224
227
}
225
228
226
229
this . onRunComplete = function ( browsers , results ) {
227
- var checkedCoverage = { }
230
+ const checkedCoverage = { }
228
231
229
- reporters . forEach ( function ( reporterConfig ) {
232
+ for ( const reporterConfig of reporters ) {
230
233
browsers . forEach ( function ( browser ) {
231
- var coverageMap = coverageMaps [ browser . id ]
232
-
234
+ const coverageMap = coverageMaps [ browser . id ]
233
235
if ( ! coverageMap ) {
234
236
return
235
237
}
236
238
237
- var mainDir = reporterConfig . dir || config . dir
238
- var subDir = reporterConfig . subdir || config . subdir
239
- var browserName = browser . name . replace ( ':' , '' )
240
- var simpleOutputDir = generateOutputDir ( browserName , mainDir , subDir )
241
- var resolvedOutputDir = path . resolve ( basePath , simpleOutputDir )
239
+ const mainDir = reporterConfig . dir || config . dir
240
+ const subDir = reporterConfig . subdir || config . subdir
241
+ const outputPath = generateOutputPath ( basePath , browser . name , mainDir , subDir )
242
242
243
- var outputDir = helper . normalizeWinPath ( resolvedOutputDir )
244
- var options = helper . merge ( config , reporterConfig , {
245
- dir : outputDir ,
243
+ const options = helper . merge ( config , reporterConfig , {
244
+ dir : outputPath ,
246
245
subdir : '' ,
247
246
browser : browser ,
248
247
emitter : emitter
249
248
} )
250
- var remappedCoverageMap = sourceMapStore . transformCoverage ( coverageMap ) . map
249
+ const remappedCoverageMap = sourceMapStore . transformCoverage ( coverageMap ) . map
251
250
252
251
// If config.check is defined, check coverage levels for each browser
253
252
if ( hasOwnProperty . call ( config , 'check' ) && ! checkedCoverage [ browser . id ] ) {
254
253
checkedCoverage [ browser . id ] = true
255
254
var coverageFailed = checkCoverage ( browser , remappedCoverageMap )
256
- if ( coverageFailed ) {
257
- if ( results ) {
258
- results . exitCode = 1
259
- }
255
+ if ( coverageFailed && results ) {
256
+ results . exitCode = 1
260
257
}
261
258
}
262
259
263
- var context = istanbulLibReport . createContext ( options )
264
- var tree = istanbulLibReport . summarizers . pkg ( remappedCoverageMap )
265
- var report = reports . create ( reporterConfig . type || 'html' , options )
260
+ const context = istanbulLibReport . createContext ( options )
261
+ const tree = istanbulLibReport . summarizers . pkg ( remappedCoverageMap )
262
+ const report = reports . create ( reporterConfig . type || 'html' , options )
266
263
267
264
// // If reporting to console or in-memory skip directory creation
268
- var toDisk = ! reporterConfig . type || ! reporterConfig . type . match ( / ^ ( t e x t | t e x t - s u m m a r y | i n - m e m o r y ) $ / )
265
+ const toDisk = ! reporterConfig . type || ! reporterConfig . type . match ( / ^ ( t e x t | t e x t - s u m m a r y | i n - m e m o r y ) $ / )
269
266
270
267
if ( ! toDisk && reporterConfig . file === undefined ) {
271
268
tree . visit ( report , context )
272
269
return
273
270
}
274
271
275
- helper . mkdirIfNotExists ( outputDir , function ( ) {
276
- log . debug ( 'Writing coverage to %s' , outputDir )
272
+ helper . mkdirIfNotExists ( outputPath , function ( ) {
273
+ log . debug ( 'Writing coverage to %s' , outputPath )
277
274
tree . visit ( report , context )
278
275
} )
279
276
} )
280
- } )
277
+ }
281
278
}
282
279
283
280
this . onExit = function ( done ) {
0 commit comments