check-coverage.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. var NYC
  2. try {
  3. NYC = require('../../index.covered.js')
  4. } catch (e) {
  5. NYC = require('../../index.js')
  6. }
  7. exports.command = 'check-coverage'
  8. exports.describe = 'check whether coverage is within thresholds provided'
  9. exports.builder = function (yargs) {
  10. yargs
  11. .option('branches', {
  12. default: 0,
  13. description: 'what % of branches must be covered?'
  14. })
  15. .option('functions', {
  16. default: 0,
  17. description: 'what % of functions must be covered?'
  18. })
  19. .option('lines', {
  20. default: 90,
  21. description: 'what % of lines must be covered?'
  22. })
  23. .option('statements', {
  24. default: 0,
  25. description: 'what % of statements must be covered?'
  26. })
  27. .option('per-file', {
  28. default: false,
  29. description: 'check thresholds per file'
  30. })
  31. .example('$0 check-coverage --lines 95', "check whether the JSON in nyc's output folder meets the thresholds provided")
  32. }
  33. exports.handler = function (argv) {
  34. process.env.NYC_CWD = process.cwd()
  35. ;(new NYC(argv)).checkCoverage({
  36. lines: argv.lines,
  37. functions: argv.functions,
  38. branches: argv.branches,
  39. statements: argv.statements
  40. }, argv['per-file'])
  41. }