Skip to content
Permalink
Browse files
feat: --100 (#332)
  • Loading branch information
gr2m committed Oct 6, 2021
1 parent 1866b93 commit 4205f2f33585693d82c2500d0d6850571965bb8b
Showing with 205 additions and 33 deletions.
  1. +18 −0 README.md
  2. +8 −0 lib/commands/check-coverage.js
  3. +8 −0 lib/commands/report.js
  4. +19 −0 lib/parse-args.js
  5. +26 −0 test/integration.js
  6. +62 −0 test/integration.js.snap
  7. +64 −33 test/integration.js_10.snap
@@ -80,6 +80,24 @@ To check thresholds on a per-file basis run:
c8 check-coverage --lines 95 --per-file
```

If you want to check for 100% coverage across all dimensions, use `--100`:

```shell
c8 --100 npm test
```

Is equivalent to

```shell
c8 --check-coverage --lines 100 --functions 100 --branches 100 --statements 100 npm test
```

The `--100` flag can be set for the `check-coverage` as well:

```shell
c8 check-coverage --100
```

## Ignoring Uncovered Lines, Functions, and Blocks

Sometimes you might find yourself wanting to ignore uncovered portions of your
@@ -11,6 +11,14 @@ exports.builder = function (yargs) {
}

exports.handler = function (argv) {
// TODO: this is a workaround until yargs gets upgraded to v17, see https://github.com/bcoe/c8/pull/332#discussion_r721636191
if (argv['100']) {
argv.lines = 100
argv.functions = 100
argv.branches = 100
argv.statements = 100
}

const report = Report({
include: argv.include,
exclude: argv.exclude,
@@ -10,6 +10,14 @@ exports.handler = async function (argv) {
}

exports.outputReport = async function (argv) {
// TODO: this is a workaround until yargs gets upgraded to v17, see https://github.com/bcoe/c8/pull/332#discussion_r721636191
if (argv['100']) {
argv.checkCoverage = 100
argv.lines = 100
argv.functions = 100
argv.branches = 100
argv.statements = 100
}
const report = Report({
include: argv.include,
exclude: argv.exclude,
@@ -107,6 +107,12 @@ function buildYargs (withCommands = false) {
description: 'check thresholds per file',
type: 'boolean'
})
.option('100', {
default: false,
group: 'Coverage thresholds',
description: 'shortcut for --check-coverage --lines 100 --functions 100 --branches 100 --statements 100',
type: 'boolean'
})
.option('temp-directory', {
describe: 'directory V8 coverage data is written to and read from',
default: process.env.NODE_V8_COVERAGE
@@ -145,6 +151,19 @@ function buildYargs (withCommands = false) {
})
.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
// yargs.middleware((argv) => {
// if (!argv['100']) return argv

// return {
// ...argv,
// branches: 100,
// functions: 100,
// lines: 100,
// statements: 100,
// }
// })

const checkCoverage = require('./commands/check-coverage')
const report = require('./commands/report')
if (withCommands) {
@@ -211,6 +211,32 @@ describe('c8', () => {
status.should.equal(1)
output.toString('utf8').should.matchSnapshot()
})

it('--100', () => {
const { output, status } = spawnSync(nodePath, [
c8Path,
'--exclude="test/*.js"',
'--temp-directory=tmp/check-coverage',
'--100',
nodePath,
require.resolve('./fixtures/normal')
])

status.should.equal(1)
output.toString('utf8').should.matchSnapshot()
})

it('check-coverage command with --100', () => {
const { output, status } = spawnSync(nodePath, [
c8Path,
'check-coverage',
'--exclude="test/*.js"',
'--temp-directory=tmp/check-coverage',
'--100'
])
status.should.equal(1)
output.toString('utf8').should.matchSnapshot()
})
})

describe('report', () => {

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

0 comments on commit 4205f2f

Please sign in to comment.