Skip to content

Commit

Permalink
feat: allow relative paths to be optionally included
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin committed Sep 11, 2018
1 parent df6084b commit 3806c79
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion bin/c8.js
Expand Up @@ -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
})
}
5 changes: 5 additions & 0 deletions lib/parse-args.js
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions lib/report.js
Expand Up @@ -14,7 +14,8 @@ class Report {
reporter,
tempDirectory,
watermarks,
resolve
resolve,
omitRelative
}) {
this.reporter = reporter
this.tempDirectory = tempDirectory
Expand All @@ -24,6 +25,7 @@ class Report {
exclude: exclude,
include: include
})
this.omitRelative = omitRelative
}
run () {
const map = this._getCoverageMapFromAllCoverageFiles()
Expand All @@ -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],
Expand Down
12 changes: 12 additions & 0 deletions test/integration.js
Expand Up @@ -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/
)
})
})

0 comments on commit 3806c79

Please sign in to comment.