Skip to content

Commit

Permalink
feat: support --check-coverage for reports (bcoe#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored Jan 24, 2019
1 parent 38b36a8 commit b542930
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 16 deletions.
4 changes: 1 addition & 3 deletions bin/c8.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
const fs = require('fs')
const foreground = require('foreground-child')
const { outputReport } = require('../lib/commands/report')
const { checkCoverages } = require('../lib/commands/check-coverage')
const { promisify } = require('util')
const rimraf = require('rimraf')
const {
Expand All @@ -29,8 +28,7 @@ let argv = buildYargs().parse(instrumenterArgs)

process.env.NODE_V8_COVERAGE = argv.tempDirectory
foreground(hideInstrumenterArgs(argv), () => {
const report = outputReport(argv)
if (argv.checkCoverage) checkCoverages(argv, report)
outputReport(argv)
})
}
})()
3 changes: 2 additions & 1 deletion lib/commands/report.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { checkCoverages } = require('./check-coverage')
const Report = require('../report')

exports.command = 'report'
Expand All @@ -20,5 +21,5 @@ exports.outputReport = function (argv) {
wrapperLength: argv.wrapperLength
})
report.run()
return report
if (argv.checkCoverage) checkCoverages(argv, report)
}
25 changes: 25 additions & 0 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,29 @@ describe('c8', () => {
output.toString('utf8').should.matchSnapshot()
})
})

describe('report', () => {
it('generates report from existing temporary files', () => {
const { output } = spawnSync(nodePath, [
c8Path,
'report',
'--exclude="test/*.js"',
'--clean=false'
])
output.toString('utf8').should.matchSnapshot()
})

it('supports --check-coverage, when generating reports', () => {
const { output, status } = spawnSync(nodePath, [
c8Path,
'report',
'--check-coverage',
'--lines=101',
'--exclude="test/*.js"',
'--clean=false'
])
status.should.equal(1)
output.toString('utf8').should.matchSnapshot()
})
})
})
69 changes: 57 additions & 12 deletions test/integration.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ hey
--------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------|----------|----------|----------|----------|-------------------|
All files | 95.42 | 75.9 | 89.66 | 95.42 | |
bin | 86.49 | 71.43 | 100 | 86.49 | |
c8.js | 86.49 | 71.43 | 100 | 86.49 | 26,34,35,36,37 |
All files | 95.41 | 76.83 | 89.66 | 95.41 | |
bin | 85.71 | 83.33 | 100 | 85.71 | |
c8.js | 85.71 | 83.33 | 100 | 85.71 | 25,32,33,34,35 |
lib | 97.05 | 65 | 100 | 97.05 | |
parse-args.js | 98.35 | 53.85 | 100 | 98.35 | 97,98 |
report.js | 96 | 70.37 | 100 | 96 |... 08,134,135,136 |
lib/commands | 97.65 | 84.21 | 87.5 | 97.65 | |
lib/commands | 97.67 | 84.21 | 87.5 | 97.67 | |
check-coverage.js | 100 | 92.86 | 100 | 100 | 17 |
report.js | 92 | 60 | 50 | 92 | 8,9 |
report.js | 92.31 | 60 | 50 | 92.31 | 9,10 |
test/fixtures | 90.91 | 94.12 | 75 | 90.91 | |
async.js | 100 | 100 | 100 | 100 | |
multiple-spawn.js | 100 | 100 | 100 | 100 | |
normal.js | 76 | 75 | 33.33 | 76 | 14,15,16,18,19,20 |
subprocess.js | 100 | 100 | 100 | 100 | |
--------------------|----------|----------|----------|----------|-------------------|
,ERROR: Coverage for lines (95.42%) does not meet global threshold (101%)
,ERROR: Coverage for lines (95.41%) does not meet global threshold (101%)
"
`;

Expand All @@ -40,7 +40,7 @@ ERROR: Coverage for lines (76%) does not meet threshold (80%) for test/fixtures/
exports[`c8 check-coverage exits with 0 if coverage within threshold 1`] = `",,"`;

exports[`c8 check-coverage exits with 1 if coverage is below threshold 1`] = `
",,ERROR: Coverage for lines (94.99%) does not meet global threshold (101%)
",,ERROR: Coverage for lines (94.98%) does not meet global threshold (101%)
"
`;

Expand All @@ -52,15 +52,15 @@ second
--------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------|----------|----------|----------|----------|-------------------|
All files | 84.53 | 67.16 | 74.07 | 84.53 | |
bin | 86.49 | 57.14 | 100 | 86.49 | |
c8.js | 86.49 | 57.14 | 100 | 86.49 | 26,34,35,36,37 |
All files | 84.5 | 68.18 | 74.07 | 84.5 | |
bin | 85.71 | 66.67 | 100 | 85.71 | |
c8.js | 85.71 | 66.67 | 100 | 85.71 | 25,32,33,34,35 |
lib | 95.57 | 55.56 | 100 | 95.57 | |
parse-args.js | 96.69 | 41.67 | 100 | 96.69 | 83,84,97,98 |
report.js | 94.67 | 62.5 | 100 | 94.67 |... 08,134,135,136 |
lib/commands | 43.53 | 71.43 | 16.67 | 43.53 | |
lib/commands | 44.19 | 71.43 | 16.67 | 44.19 | |
check-coverage.js | 23.33 | 100 | 0 | 23.33 |... 55,56,57,58,59 |
report.js | 92 | 60 | 50 | 92 | 8,9 |
report.js | 92.31 | 60 | 50 | 92.31 | 9,10 |
test/fixtures | 90.91 | 94.12 | 75 | 90.91 | |
async.js | 100 | 100 | 100 | 100 | |
multiple-spawn.js | 100 | 100 | 100 | 100 | |
Expand All @@ -70,6 +70,51 @@ All files | 84.53 | 67.16 | 74.07 | 84.53 |
,"
`;

exports[`c8 report generates report from existing temporary files 1`] = `
",--------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------|----------|----------|----------|----------|-------------------|
All files | 95.41 | 79.76 | 89.66 | 95.41 | |
bin | 85.71 | 85.71 | 100 | 85.71 | |
c8.js | 85.71 | 85.71 | 100 | 85.71 | 25,32,33,34,35 |
lib | 97.05 | 69.05 | 100 | 97.05 | |
parse-args.js | 98.35 | 53.85 | 100 | 98.35 | 97,98 |
report.js | 96 | 75.86 | 100 | 96 |... 08,134,135,136 |
lib/commands | 97.67 | 88.89 | 87.5 | 97.67 | |
check-coverage.js | 100 | 92.31 | 100 | 100 | 17 |
report.js | 92.31 | 80 | 50 | 92.31 | 9,10 |
test/fixtures | 90.91 | 94.12 | 75 | 90.91 | |
async.js | 100 | 100 | 100 | 100 | |
multiple-spawn.js | 100 | 100 | 100 | 100 | |
normal.js | 76 | 75 | 33.33 | 76 | 14,15,16,18,19,20 |
subprocess.js | 100 | 100 | 100 | 100 | |
--------------------|----------|----------|----------|----------|-------------------|
,"
`;

exports[`c8 report supports --check-coverage, when generating reports 1`] = `
",--------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------|----------|----------|----------|----------|-------------------|
All files | 95.85 | 79.76 | 93.1 | 95.85 | |
bin | 85.71 | 83.33 | 100 | 85.71 | |
c8.js | 85.71 | 83.33 | 100 | 85.71 | 25,32,33,34,35 |
lib | 97.05 | 69.05 | 100 | 97.05 | |
parse-args.js | 98.35 | 53.85 | 100 | 98.35 | 97,98 |
report.js | 96 | 75.86 | 100 | 96 |... 08,134,135,136 |
lib/commands | 100 | 89.47 | 100 | 100 | |
check-coverage.js | 100 | 92.31 | 100 | 100 | 17 |
report.js | 100 | 83.33 | 100 | 100 | 16 |
test/fixtures | 90.91 | 94.12 | 75 | 90.91 | |
async.js | 100 | 100 | 100 | 100 | |
multiple-spawn.js | 100 | 100 | 100 | 100 | |
normal.js | 76 | 75 | 33.33 | 76 | 14,15,16,18,19,20 |
subprocess.js | 100 | 100 | 100 | 100 | |
--------------------|----------|----------|----------|----------|-------------------|
,ERROR: Coverage for lines (95.85%) does not meet global threshold (101%)
"
`;

exports[`c8 reports coverage for script that exits normally 1`] = `
",hey
i am a line of code
Expand Down

0 comments on commit b542930

Please sign in to comment.