Skip to content

Commit

Permalink
refactor: Increasing code coverage of lib/parse-args.js to 100%. (bco…
Browse files Browse the repository at this point in the history
…e#447)

test: Adding a test case for NODE_V8_COVERAGE and changing the describe block title. (bcoe#447)
  • Loading branch information
mcknasty committed Jan 28, 2023
1 parent 3646e6e commit fbe5d72
Show file tree
Hide file tree
Showing 5 changed files with 961 additions and 3,655 deletions.
18 changes: 5 additions & 13 deletions lib/parse-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ 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) {
if (typeof process.env.NODE_V8_COVERAGE !== 'string') {
process.env.NODE_V8_COVERAGE = process.cwd() + '/coverage/tmp'
}
const yargs = Yargs([])
.usage('$0 [opts] [script] [opts]')
.options('config', {
Expand Down Expand Up @@ -126,7 +128,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: process.env.NODE_V8_COVERAGE,
type: 'string'
})
.option('clean', {
default: true,
Expand Down Expand Up @@ -154,12 +157,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 +188,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
Loading

0 comments on commit fbe5d72

Please sign in to comment.