From 3806c79dd189bfa4c66f5a1e4f5305f3c9eac263 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Mon, 10 Sep 2018 22:32:25 -0700 Subject: [PATCH] feat: allow relative paths to be optionally included --- bin/c8.js | 3 ++- lib/parse-args.js | 5 +++++ lib/report.js | 6 ++++-- test/integration.js | 12 ++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/bin/c8.js b/bin/c8.js index 432d7ea3..bbd4220c 100755 --- a/bin/c8.js +++ b/bin/c8.js @@ -34,6 +34,7 @@ function outputReport () { reporter: Array.isArray(argv.reporter) ? argv.reporter : [argv.reporter], tempDirectory: argv.tempDirectory, watermarks: argv.watermarks, - resolve: argv.resolve + resolve: argv.resolve, + omitRelative: argv.omitRelative }) } diff --git a/lib/parse-args.js b/lib/parse-args.js index ebe2dd55..1c629264 100644 --- a/lib/parse-args.js +++ b/lib/parse-args.js @@ -36,6 +36,11 @@ yargs() default: '', describe: 'resolve paths to alternate base directory' }) + .option('omit-relative', { + default: true, + type: 'boolean', + describe: 'omit any paths that are not absolute, e.g., internal/net.js' + }) .command('report', 'read V8 coverage data from temp and output report') .pkgConf('c8') .config(config) diff --git a/lib/report.js b/lib/report.js index 7e3ae77c..6623d713 100644 --- a/lib/report.js +++ b/lib/report.js @@ -14,7 +14,8 @@ class Report { reporter, tempDirectory, watermarks, - resolve + resolve, + omitRelative }) { this.reporter = reporter this.tempDirectory = tempDirectory @@ -24,6 +25,7 @@ class Report { exclude: exclude, include: include }) + this.omitRelative = omitRelative } run () { const map = this._getCoverageMapFromAllCoverageFiles() @@ -44,7 +46,7 @@ class Report { this._loadReports().forEach((report) => { report.result.forEach((result) => { if (this.exclude.shouldInstrument(result.url) && - isAbsolute(result.url)) { + (!this.omitRelative || isAbsolute(result.url))) { if (mergedResults[result.url]) { mergedResults[result.url] = v8CoverageMerge( mergedResults[result.url], diff --git a/test/integration.js b/test/integration.js index 67d5a964..73908cdb 100644 --- a/test/integration.js +++ b/test/integration.js @@ -37,4 +37,16 @@ All files | 100 | 77.78 | 100 | 100 | subprocess.js | 100 | 71.43 | 100 | 100 | 9,13 | -------------------|----------|----------|----------|----------|-------------------|`) }) + + it('omit-relative can be set to false', () => { + const { output } = spawnSync(c8Path, [ + '--exclude="test/*.js"', + '--omit-relative=false', + process.execPath, + require.resolve('./fixtures/multiple-spawn') + ]) + output.toString('utf8').should.match( + /Error: ENOENT: no such file or directory.*loaders\.js/ + ) + }) })