Skip to content

Commit

Permalink
Print Derived Configuration Report (bcoe#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 Jun 12, 2024
1 parent e3560e1 commit e543c63
Show file tree
Hide file tree
Showing 12 changed files with 1,535 additions and 411 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`
| `--experimental-monocart` | see [section below](#using-monocart-coverage-reports-experimental) for more info | `boolean` | `false` |

## 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,13 +160,24 @@ 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'
})
.option('experimental-monocart', {
default: false,
type: 'boolean',
describe: 'Use Monocart coverage reports'
})
.pkgConf('c8')
.demandCommand(1)
.check((argv) => {
if (!argv.tempDirectory) {
argv.tempDirectory = resolve(argv.reportsDir, 'tmp')
Expand All @@ -186,6 +199,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 e543c63

Please sign in to comment.