report.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. var NYC
  2. try {
  3. NYC = require('../../index.covered.js')
  4. } catch (e) {
  5. NYC = require('../../index.js')
  6. }
  7. exports.command = 'report'
  8. exports.describe = 'run coverage report for .nyc_output'
  9. exports.builder = function (yargs) {
  10. return yargs
  11. .option('reporter', {
  12. alias: 'r',
  13. describe: 'coverage reporter(s) to use',
  14. default: 'text'
  15. })
  16. .option('report-dir', {
  17. describe: 'directory to output coverage reports in',
  18. default: 'coverage'
  19. })
  20. .option('temp-dir', {
  21. alias: 't',
  22. describe: 'directory to read raw coverage information from',
  23. default: './.nyc_output'
  24. })
  25. .option('temp-directory', {
  26. hidden: true
  27. })
  28. .option('show-process-tree', {
  29. describe: 'display the tree of spawned processes',
  30. default: false,
  31. type: 'boolean'
  32. })
  33. .option('skip-empty', {
  34. describe: 'don\'t show empty files (no lines of code) in report',
  35. default: false,
  36. type: 'boolean',
  37. global: false
  38. })
  39. .option('check-coverage', {
  40. type: 'boolean',
  41. default: false,
  42. describe: 'check whether coverage is within thresholds provided',
  43. global: false
  44. })
  45. .option('branches', {
  46. default: 0,
  47. description: 'what % of branches must be covered?',
  48. global: false
  49. })
  50. .option('functions', {
  51. default: 0,
  52. description: 'what % of functions must be covered?',
  53. global: false
  54. })
  55. .option('lines', {
  56. default: 90,
  57. description: 'what % of lines must be covered?',
  58. global: false
  59. })
  60. .option('statements', {
  61. default: 0,
  62. description: 'what % of statements must be covered?',
  63. global: false
  64. })
  65. .option('per-file', {
  66. default: false,
  67. type: 'boolean',
  68. description: 'check thresholds per file',
  69. global: false
  70. })
  71. .example('$0 report --reporter=lcov', 'output an HTML lcov report to ./coverage')
  72. }
  73. exports.handler = function (argv) {
  74. process.env.NYC_CWD = process.cwd()
  75. var nyc = new NYC(argv)
  76. nyc.report()
  77. if (argv.checkCoverage) {
  78. nyc.checkCoverage({
  79. lines: argv.lines,
  80. functions: argv.functions,
  81. branches: argv.branches,
  82. statements: argv.statements
  83. }, argv['per-file'])
  84. }
  85. }