@@ -7,6 +7,7 @@ const { readFileSync, writeFileSync, existsSync } = require('fs')
7
7
const { isAbsolute, resolve, join } = require ( 'path' )
8
8
const debug = require ( 'debug' ) ( 'code-coverage' )
9
9
const chalk = require ( 'chalk' )
10
+ const globby = require ( 'globby' )
10
11
11
12
function combineNycOptions ( {
12
13
pkgNycOptions,
@@ -264,12 +265,51 @@ function tryFindingLocalFiles(nycFilename) {
264
265
}
265
266
}
266
267
268
+ /**
269
+ * If the website or unit tests did not load ALL files we need to
270
+ * include, then we should include the missing files ourselves
271
+ * before generating the report.
272
+ *
273
+ * @see https://github.com/cypress-io/code-coverage/issues/207
274
+ */
275
+ function includeAllFiles ( nycOptions ) {
276
+ debug ( 'include all files options: %o' , {
277
+ all : nycOptions . all ,
278
+ include : nycOptions . include ,
279
+ exclude : nycOptions . exclude
280
+ } )
281
+
282
+ let patterns = [ ]
283
+ if ( Array . isArray ( nycOptions . include ) ) {
284
+ patterns = patterns . concat ( nycOptions . include )
285
+ } else if ( typeof nycOptions . include === 'string' ) {
286
+ patterns . push ( nycOptions . include )
287
+ }
288
+
289
+ if ( Array . isArray ( nycOptions . exclude ) ) {
290
+ const negated = nycOptions . exclude . map ( s => '!' + s )
291
+ patterns = patterns . concat ( negated )
292
+ } else if ( typeof nycOptions . exclude === 'string' ) {
293
+ patterns . push ( '!' + nycOptions . exclude )
294
+ }
295
+ // always exclude node_modules
296
+ // https://github.com/istanbuljs/nyc#including-files-within-node_modules
297
+ patterns . push ( '!**/node_modules/**' )
298
+
299
+ debug ( 'searching files to include using patterns %o' , patterns )
300
+
301
+ const allFiles = globby . sync ( patterns )
302
+ debug ( 'found these files %o' , allFiles )
303
+ // TODO check if any of the files to include are missing from NYC output JSON file
304
+ }
305
+
267
306
module . exports = {
268
307
showNycInfo,
269
308
resolveRelativePaths,
270
309
checkAllPathsNotFound,
271
310
tryFindingLocalFiles,
272
311
readNycOptions,
273
312
combineNycOptions,
274
- defaultNycOptions
313
+ defaultNycOptions,
314
+ includeAllFiles
275
315
}
0 commit comments