@@ -235,24 +235,35 @@ function tryFindingLocalFiles(nycFilename) {
235
235
}
236
236
237
237
/**
238
- * If the website or unit tests did not load ALL files we need to
239
- * include, then we should include the missing files ourselves
240
- * before generating the report.
241
- *
242
- * @see https://github.com/cypress-io/code-coverage/issues/207
238
+ * Tries to find source files to be included in the final coverage report
239
+ * using NYC options: extension list, include and exclude.
243
240
*/
244
- function includeAllFiles ( nycFilename , nycOptions ) {
241
+ function findSourceFiles ( nycOptions ) {
245
242
debug ( 'include all files options: %o' , {
246
243
all : nycOptions . all ,
247
244
include : nycOptions . include ,
248
- exclude : nycOptions . exclude
245
+ exclude : nycOptions . exclude ,
246
+ extension : nycOptions . extension
249
247
} )
250
248
249
+ if ( ! Array . isArray ( nycOptions . extension ) ) {
250
+ console . error (
251
+ 'Expected NYC "extension" option to be a list of file extensions'
252
+ )
253
+ console . error ( nycOptions )
254
+ return [ ]
255
+ }
256
+
251
257
let patterns = [ ]
252
258
if ( Array . isArray ( nycOptions . include ) ) {
253
259
patterns = patterns . concat ( nycOptions . include )
254
260
} else if ( typeof nycOptions . include === 'string' ) {
255
261
patterns . push ( nycOptions . include )
262
+ } else {
263
+ debug ( 'using default list of extensions' )
264
+ nycOptions . extension . forEach ( extension => {
265
+ patterns . push ( '**/*' + extension )
266
+ } )
256
267
}
257
268
258
269
if ( Array . isArray ( nycOptions . exclude ) ) {
@@ -268,7 +279,30 @@ function includeAllFiles(nycFilename, nycOptions) {
268
279
debug ( 'searching files to include using patterns %o' , patterns )
269
280
270
281
const allFiles = globby . sync ( patterns , { absolute : true } )
271
- debug ( 'found these files %o' , allFiles )
282
+ return allFiles
283
+ }
284
+ /**
285
+ * If the website or unit tests did not load ALL files we need to
286
+ * include, then we should include the missing files ourselves
287
+ * before generating the report.
288
+ *
289
+ * @see https://github.com/cypress-io/code-coverage/issues/207
290
+ */
291
+ function includeAllFiles ( nycFilename , nycOptions ) {
292
+ if ( ! nycOptions . all ) {
293
+ debug ( 'NYC "all" option is not set, skipping including all files' )
294
+ return
295
+ }
296
+
297
+ const allFiles = findSourceFiles ( nycOptions )
298
+ if ( debug . enabled ) {
299
+ debug ( 'found %d file(s)' , allFiles . length )
300
+ console . error ( allFiles . join ( '\n' ) )
301
+ }
302
+ if ( ! allFiles . length ) {
303
+ debug ( 'no files found, hoping for the best' )
304
+ return
305
+ }
272
306
273
307
const nycCoverage = JSON . parse ( readFileSync ( nycFilename , 'utf8' ) )
274
308
const coverageKeys = Object . keys ( nycCoverage )
0 commit comments