Skip to content

Commit b542930

Browse files
authored
feat: support --check-coverage for reports (bcoe#60)
1 parent 38b36a8 commit b542930

File tree

4 files changed

+85
-16
lines changed

4 files changed

+85
-16
lines changed

bin/c8.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
const fs = require('fs')
55
const foreground = require('foreground-child')
66
const { outputReport } = require('../lib/commands/report')
7-
const { checkCoverages } = require('../lib/commands/check-coverage')
87
const { promisify } = require('util')
98
const rimraf = require('rimraf')
109
const {
@@ -29,8 +28,7 @@ let argv = buildYargs().parse(instrumenterArgs)
2928

3029
process.env.NODE_V8_COVERAGE = argv.tempDirectory
3130
foreground(hideInstrumenterArgs(argv), () => {
32-
const report = outputReport(argv)
33-
if (argv.checkCoverage) checkCoverages(argv, report)
31+
outputReport(argv)
3432
})
3533
}
3634
})()

lib/commands/report.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const { checkCoverages } = require('./check-coverage')
12
const Report = require('../report')
23

34
exports.command = 'report'
@@ -20,5 +21,5 @@ exports.outputReport = function (argv) {
2021
wrapperLength: argv.wrapperLength
2122
})
2223
report.run()
23-
return report
24+
if (argv.checkCoverage) checkCoverages(argv, report)
2425
}

test/integration.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,29 @@ describe('c8', () => {
9797
output.toString('utf8').should.matchSnapshot()
9898
})
9999
})
100+
101+
describe('report', () => {
102+
it('generates report from existing temporary files', () => {
103+
const { output } = spawnSync(nodePath, [
104+
c8Path,
105+
'report',
106+
'--exclude="test/*.js"',
107+
'--clean=false'
108+
])
109+
output.toString('utf8').should.matchSnapshot()
110+
})
111+
112+
it('supports --check-coverage, when generating reports', () => {
113+
const { output, status } = spawnSync(nodePath, [
114+
c8Path,
115+
'report',
116+
'--check-coverage',
117+
'--lines=101',
118+
'--exclude="test/*.js"',
119+
'--clean=false'
120+
])
121+
status.should.equal(1)
122+
output.toString('utf8').should.matchSnapshot()
123+
})
124+
})
100125
})

test/integration.js.snap

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ hey
1212
--------------------|----------|----------|----------|----------|-------------------|
1313
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
1414
--------------------|----------|----------|----------|----------|-------------------|
15-
All files | 95.42 | 75.9 | 89.66 | 95.42 | |
16-
bin | 86.49 | 71.43 | 100 | 86.49 | |
17-
c8.js | 86.49 | 71.43 | 100 | 86.49 | 26,34,35,36,37 |
15+
All files | 95.41 | 76.83 | 89.66 | 95.41 | |
16+
bin | 85.71 | 83.33 | 100 | 85.71 | |
17+
c8.js | 85.71 | 83.33 | 100 | 85.71 | 25,32,33,34,35 |
1818
lib | 97.05 | 65 | 100 | 97.05 | |
1919
parse-args.js | 98.35 | 53.85 | 100 | 98.35 | 97,98 |
2020
report.js | 96 | 70.37 | 100 | 96 |... 08,134,135,136 |
21-
lib/commands | 97.65 | 84.21 | 87.5 | 97.65 | |
21+
lib/commands | 97.67 | 84.21 | 87.5 | 97.67 | |
2222
check-coverage.js | 100 | 92.86 | 100 | 100 | 17 |
23-
report.js | 92 | 60 | 50 | 92 | 8,9 |
23+
report.js | 92.31 | 60 | 50 | 92.31 | 9,10 |
2424
test/fixtures | 90.91 | 94.12 | 75 | 90.91 | |
2525
async.js | 100 | 100 | 100 | 100 | |
2626
multiple-spawn.js | 100 | 100 | 100 | 100 | |
2727
normal.js | 76 | 75 | 33.33 | 76 | 14,15,16,18,19,20 |
2828
subprocess.js | 100 | 100 | 100 | 100 | |
2929
--------------------|----------|----------|----------|----------|-------------------|
30-
,ERROR: Coverage for lines (95.42%) does not meet global threshold (101%)
30+
,ERROR: Coverage for lines (95.41%) does not meet global threshold (101%)
3131
"
3232
`;
3333

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

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

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

73+
exports[`c8 report generates report from existing temporary files 1`] = `
74+
",--------------------|----------|----------|----------|----------|-------------------|
75+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
76+
--------------------|----------|----------|----------|----------|-------------------|
77+
All files | 95.41 | 79.76 | 89.66 | 95.41 | |
78+
bin | 85.71 | 85.71 | 100 | 85.71 | |
79+
c8.js | 85.71 | 85.71 | 100 | 85.71 | 25,32,33,34,35 |
80+
lib | 97.05 | 69.05 | 100 | 97.05 | |
81+
parse-args.js | 98.35 | 53.85 | 100 | 98.35 | 97,98 |
82+
report.js | 96 | 75.86 | 100 | 96 |... 08,134,135,136 |
83+
lib/commands | 97.67 | 88.89 | 87.5 | 97.67 | |
84+
check-coverage.js | 100 | 92.31 | 100 | 100 | 17 |
85+
report.js | 92.31 | 80 | 50 | 92.31 | 9,10 |
86+
test/fixtures | 90.91 | 94.12 | 75 | 90.91 | |
87+
async.js | 100 | 100 | 100 | 100 | |
88+
multiple-spawn.js | 100 | 100 | 100 | 100 | |
89+
normal.js | 76 | 75 | 33.33 | 76 | 14,15,16,18,19,20 |
90+
subprocess.js | 100 | 100 | 100 | 100 | |
91+
--------------------|----------|----------|----------|----------|-------------------|
92+
,"
93+
`;
94+
95+
exports[`c8 report supports --check-coverage, when generating reports 1`] = `
96+
",--------------------|----------|----------|----------|----------|-------------------|
97+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
98+
--------------------|----------|----------|----------|----------|-------------------|
99+
All files | 95.85 | 79.76 | 93.1 | 95.85 | |
100+
bin | 85.71 | 83.33 | 100 | 85.71 | |
101+
c8.js | 85.71 | 83.33 | 100 | 85.71 | 25,32,33,34,35 |
102+
lib | 97.05 | 69.05 | 100 | 97.05 | |
103+
parse-args.js | 98.35 | 53.85 | 100 | 98.35 | 97,98 |
104+
report.js | 96 | 75.86 | 100 | 96 |... 08,134,135,136 |
105+
lib/commands | 100 | 89.47 | 100 | 100 | |
106+
check-coverage.js | 100 | 92.31 | 100 | 100 | 17 |
107+
report.js | 100 | 83.33 | 100 | 100 | 16 |
108+
test/fixtures | 90.91 | 94.12 | 75 | 90.91 | |
109+
async.js | 100 | 100 | 100 | 100 | |
110+
multiple-spawn.js | 100 | 100 | 100 | 100 | |
111+
normal.js | 76 | 75 | 33.33 | 76 | 14,15,16,18,19,20 |
112+
subprocess.js | 100 | 100 | 100 | 100 | |
113+
--------------------|----------|----------|----------|----------|-------------------|
114+
,ERROR: Coverage for lines (95.85%) does not meet global threshold (101%)
115+
"
116+
`;
117+
73118
exports[`c8 reports coverage for script that exits normally 1`] = `
74119
",hey
75120
i am a line of code

0 commit comments

Comments
 (0)