Skip to content

Commit

Permalink
Print Derived Configuration Report (#517)
Browse files Browse the repository at this point in the history
feat: print derived config variables
feat: print derived config variables in json
test: 16 new unit tests to support features
test: 1 skipped unit test for discovered bug in yargs with reports param
  • Loading branch information
mcknasty committed Feb 18, 2024
1 parent bf3073b commit b33e8e7
Show file tree
Hide file tree
Showing 12 changed files with 1,543 additions and 546 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Here is a list of common options. Run `c8 --help` for the full list and document
| `--per-file` | check thresholds per file | `boolean` | `false` |
| `--temp-directory` | directory V8 coverage data is written to and read from | `string` | `process.env.NODE_V8_COVERAGE` |
| `--clean` | should temp files be deleted before script execution | `boolean` | `true` |
| `--print-config` | prints the derived configuration between defaults and a detected configuration file or a file passed as an argument | `boolean` | `false`
| `--print-config-format` | format in which to print the derived configuration. Either text or json. | `string` | `text`

## Checking for "full" source coverage using `--all`

Expand Down
19 changes: 18 additions & 1 deletion lib/parse-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const { applyExtends } = require('yargs/helpers')
const parser = require('yargs-parser')
const { resolve } = require('path')

const { printConfig } = require('./print-config.js')

function buildYargs (withCommands = false) {
const yargs = Yargs([])
.usage('$0 [opts] [script] [opts]')
Expand Down Expand Up @@ -158,8 +160,19 @@ function buildYargs (withCommands = false) {
describe: 'supplying --merge-async will merge all v8 coverage reports asynchronously and incrementally. ' +
'This is to avoid OOM issues with Node.js runtime.'
})
.options('print-config', {
default: false,
type: 'boolean',
describe: 'Print the derived configuration between command line parameters and loaded configuration file'
})
// Todo: refactor. Use parse-args options.
.options('print-config-format', {
default: 'text',
type: 'string',
choices: ['text', 'json'],
describe: 'Format to print the configuration in. Accepted formats are either text or json'
})
.pkgConf('c8')
.demandCommand(1)
.check((argv) => {
if (!argv.tempDirectory) {
argv.tempDirectory = resolve(argv.reportsDir, 'tmp')
Expand All @@ -181,6 +194,10 @@ function buildYargs (withCommands = false) {
// }
// })

printConfig(yargs, hideInstrumenteeArgs)

yargs.demandCommand(1)

const checkCoverage = require('./commands/check-coverage')
const report = require('./commands/report')
if (withCommands) {
Expand Down
Loading

0 comments on commit b33e8e7

Please sign in to comment.