Skip to content

Commit

Permalink
Set nyc color watermarks based on check-coverage levels
Browse files Browse the repository at this point in the history
I got tired of doing --100, and then everything still looking green, making
it harder to find the test that's short on coverage.

Anything below the desired level is red.  Green starts halfway between the
desired level and 100%.
  • Loading branch information
isaacs committed Sep 29, 2019
1 parent 28e7db5 commit 7f453f5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
15 changes: 14 additions & 1 deletion bin/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,28 @@ const nycReporter = options =>
const runNyc = (cmd, programArgs, options, spawnOpts) => {
const reporter = nycReporter(options)

const branches = Math.max(+options.branches || 100, 100)
const lines = Math.max(+options.lines || 100, 100)
const functions = Math.max(+options.functions || 100, 100)
const statements = Math.max(+options.statements || 100, 100)

const args = [
nycBin,
...cmd,
...(options['show-process-tree'] ? ['--show-process-tree'] : []),
'--cache=true',
'--branches=' + options.branches,
'--branches=' + branches,
'--watermarks.branches=' + branches,
'--watermarks.branches=' + (branches + (100 - branches)/2),
'--functions=' + options.functions,
'--watermarks.functions=' + functions,
'--watermarks.functions=' + (functions + (100 - functions)/2),
'--lines=' + options.lines,
'--watermarks.lines=' + lines,
'--watermarks.lines=' + (lines + (100 - lines)/2),
'--statements=' + options.statements,
'--watermarks.statements=' + statements,
'--watermarks.statements=' + (statements + (100 - statements)/2),
...reporter,
'--extension=.js',
'--extension=.jsx',
Expand Down
10 changes: 10 additions & 0 deletions tap-snapshots/test-run-coverage.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ All files | 75 | 75 | 100 | 75 | |
`

exports[`test/run/coverage.js TAP in 100 mode, <100 is red, not yellow > text output and 100 check 1`] = `
-|-|-|-|-|-|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Lines |
-|-|-|-|-|-|
All files | 75 | 75 | 100 | 75 |  |
 ok.js  | 75 | 75 | 100 | 75 | 6 |
-|-|-|-|-|-|
`

exports[`test/run/coverage.js TAP pipe to service > human output 1`] = `
-|-|-|-|-|-|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Lines |
Expand Down
8 changes: 8 additions & 0 deletions test/run/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ t.test('report with checks', t => {
})
})

t.test('in 100 mode, <100 is red, not yellow', t => {
escape(['--100', '--coverage-report=text', '--color'], null, (er, o, e) => {
t.match(er, { code: 1 })
t.matchSnapshot(o, 'text output and 100 check', { skip: winSkip })
t.end()
})
})

t.test('pipe to service', t => {
const piper = tmpfile(t, 'piper.js', `
process.stdin.pipe(process.stderr)
Expand Down

0 comments on commit 7f453f5

Please sign in to comment.