Skip to content

Commit

Permalink
feat: support passing reporter options (bcoe#423)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin E. Coe <[email protected]>
  • Loading branch information
2 people authored and mcknasty committed Jan 28, 2023
1 parent b93b9c0 commit ddabd7c
Show file tree
Hide file tree
Showing 5 changed files with 968 additions and 3,679 deletions.
20 changes: 7 additions & 13 deletions lib/parse-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ const { readFileSync } = require('fs')
const Yargs = require('yargs/yargs')
const { applyExtends } = require('yargs/helpers')
const parser = require('yargs-parser')
const { resolve } = require('path')

function buildYargs (withCommands = false) {
let tempDir = './coverage/tmp'
if (typeof process.env.NODE_V8_COVERAGE === 'string') {
tempDir = process.env.NODE_V8_COVERAGE
}

const yargs = Yargs([])
.usage('$0 [opts] [script] [opts]')
.options('config', {
Expand Down Expand Up @@ -126,7 +130,8 @@ function buildYargs (withCommands = false) {
})
.option('temp-directory', {
describe: 'directory V8 coverage data is written to and read from',
default: process.env.NODE_V8_COVERAGE
default: tempDir,
type: 'string'
})
.option('clean', {
default: true,
Expand Down Expand Up @@ -154,12 +159,6 @@ function buildYargs (withCommands = false) {
})
.pkgConf('c8')
.demandCommand(1)
.check((argv) => {
if (!argv.tempDirectory) {
argv.tempDirectory = resolve(argv.reportsDir, 'tmp')
}
return true
})
.epilog('visit https://git.io/vHysA for list of available reporters')

// TODO: enable once yargs upgraded to v17: https://github.com/bcoe/c8/pull/332#discussion_r721636191
Expand Down Expand Up @@ -191,18 +190,13 @@ function buildYargs (withCommands = false) {
function hideInstrumenterArgs (yargv) {
let argv = process.argv.slice(1)
argv = argv.slice(argv.indexOf(yargv._[0]))
if (argv[0][0] === '-') {
argv.unshift(process.execPath)
}
return argv
}

function hideInstrumenteeArgs () {
let argv = process.argv.slice(2)
const yargv = parser(argv)

if (!yargv._.length) return argv

// drop all the arguments after the bin being
// instrumented by c8.
argv = argv.slice(0, argv.indexOf(yargv._[0]))
Expand Down
5 changes: 4 additions & 1 deletion lib/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Report {
excludeAfterRemap,
include,
reporter,
reporterOptions,
reportsDirectory,
tempDirectory,
watermarks,
Expand All @@ -32,6 +33,7 @@ class Report {
excludeNodeModules
}) {
this.reporter = reporter
this.reporterOptions = reporterOptions || {}
this.reportsDirectory = reportsDirectory
this.tempDirectory = tempDirectory
this.watermarks = watermarks
Expand Down Expand Up @@ -74,7 +76,8 @@ class Report {
reports.create(_reporter, {
skipEmpty: false,
skipFull: this.skipFull,
maxCols: process.stdout.columns || 100
maxCols: process.stdout.columns || 100,
...this.reporterOptions[_reporter]
}).execute(context)
}
}
Expand Down
Loading

0 comments on commit ddabd7c

Please sign in to comment.