Skip to content

Commit

Permalink
Merge pull request #126 from bcoe/check-coverage-combined
Browse files Browse the repository at this point in the history
add --check-coverage shorthand, which fails tests if coverage slips below threshold
  • Loading branch information
bcoe committed Jan 3, 2016
2 parents 9335691 + bb181b9 commit 972ff3c
Showing 1 changed file with 47 additions and 14 deletions.
61 changes: 47 additions & 14 deletions bin/nyc.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,27 @@ if (process.env.NYC_CWD) {
type: 'boolean',
describe: 'cache instrumentation results for improved performance'
})
.option('check-coverage', {
type: 'boolean',
default: false,
describe: 'check whether coverage is within thresholds provided'
})
.option('branches', {
default: 0,
description: 'what % of branches must be covered?'
})
.option('functions', {
default: 0,
description: 'what % of functions must be covered?'
})
.option('lines', {
default: 90,
description: 'what % of lines must be covered?'
})
.option('statements', {
default: 0,
description: 'what % of statements must be covered?'
})
.help('h')
.alias('h', 'help')
.version(require('../package.json').version)
Expand All @@ -102,18 +123,7 @@ if (process.env.NYC_CWD) {

report(argv)
} else if (~argv._.indexOf('check-coverage')) {
foreground(
process.execPath,
[
require.resolve('istanbul/lib/cli'),
'check-coverage',
'--lines=' + argv.lines,
'--functions=' + argv.functions,
'--branches=' + argv.branches,
'--statements=' + argv.statements,
path.resolve(process.cwd(), './.nyc_output/*.json')
]
)
checkCoverage(argv)
} else if (argv._.length) {
// wrap subprocesses and execute argv[1]
var nyc = (new NYC())
Expand All @@ -132,8 +142,15 @@ if (process.env.NYC_CWD) {
sw([__filename], env)

foreground(nyc.mungeArgs(argv), function (done) {
if (!argv.silent) report(argv)
return done()
if (argv.checkCoverage) {
checkCoverage(argv, function (done) {
if (!argv.silent) report(argv)
return done()
})
} else {
if (!argv.silent) report(argv)
return done()
}
})
} else {
// I don't have a clue what you're doing.
Expand All @@ -148,3 +165,19 @@ function report (argv) {
reporter: argv.reporter
})).report()
}

function checkCoverage (argv, cb) {
foreground(
process.execPath,
[
require.resolve('istanbul/lib/cli'),
'check-coverage',
'--lines=' + argv.lines,
'--functions=' + argv.functions,
'--branches=' + argv.branches,
'--statements=' + argv.statements,
path.resolve(process.cwd(), './.nyc_output/*.json')
],
cb
)
}

0 comments on commit 972ff3c

Please sign in to comment.