Skip to content

Commit 5ab31f5

Browse files
shoniebcoe
authored andcommitted
feat: allow --reports-dir to be configured (#65)
1 parent 9a7c3d9 commit 5ab31f5

5 files changed

Lines changed: 40 additions & 31 deletions

File tree

lib/commands/check-coverage.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ exports.handler = function (argv) {
1515
include: argv.include,
1616
exclude: argv.exclude,
1717
reporter: Array.isArray(argv.reporter) ? argv.reporter : [argv.reporter],
18+
reportsDirectory: argv['reports-dir'],
1819
tempDirectory: argv.tempDirectory,
1920
watermarks: argv.watermarks,
2021
resolve: argv.resolve,

lib/commands/report.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ exports.outputReport = function (argv) {
1414
include: argv.include,
1515
exclude: argv.exclude,
1616
reporter: Array.isArray(argv.reporter) ? argv.reporter : [argv.reporter],
17+
reportsDirectory: argv['reports-dir'],
1718
tempDirectory: argv.tempDirectory,
1819
watermarks: argv.watermarks,
1920
resolve: argv.resolve,

lib/parse-args.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ function buildYargs (withCommands = false) {
1515
describe: 'coverage reporter(s) to use',
1616
default: 'text'
1717
})
18+
.option('reports-dir', {
19+
alias: 'o',
20+
describe: 'reports directory, where reports is written to',
21+
default: './coverage'
22+
})
1823
.option('exclude', {
1924
alias: 'x',
2025
default: Exclude.defaultExclude,

lib/report.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@ class Report {
1414
exclude,
1515
include,
1616
reporter,
17+
reportsDirectory,
1718
tempDirectory,
1819
watermarks,
19-
resolve,
2020
omitRelative,
21-
wrapperLength
21+
wrapperLength,
22+
resolve: resolvePaths
2223
}) {
2324
this.reporter = reporter
25+
this.reportsDirectory = reportsDirectory
2426
this.tempDirectory = tempDirectory
2527
this.watermarks = watermarks
26-
this.resolve = resolve
28+
this.resolve = resolvePaths
2729
this.exclude = Exclude({
2830
exclude: exclude,
2931
include: include
@@ -34,7 +36,7 @@ class Report {
3436
run () {
3537
const map = this.getCoverageMapFromAllCoverageFiles()
3638
var context = libReport.createContext({
37-
dir: './coverage',
39+
dir: this.reportsDirectory,
3840
watermarks: this.watermarks
3941
})
4042

test/integration.js.snap

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,35 @@ hey
1212
--------------------|----------|----------|----------|----------|-------------------|
1313
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
1414
--------------------|----------|----------|----------|----------|-------------------|
15-
All files | 95.46 | 76.83 | 89.66 | 95.46 | |
15+
All files | 95.55 | 76.83 | 89.66 | 95.55 | |
1616
bin | 85.71 | 83.33 | 100 | 85.71 | |
1717
c8.js | 85.71 | 83.33 | 100 | 85.71 | 25,32,33,34,35 |
18-
lib | 97.1 | 65 | 100 | 97.1 | |
19-
parse-args.js | 98.41 | 53.85 | 100 | 98.41 | 102,103 |
20-
report.js | 96 | 70.37 | 100 | 96 |... 08,134,135,136 |
21-
lib/commands | 97.67 | 84.21 | 87.5 | 97.67 | |
18+
lib | 97.17 | 65 | 100 | 97.17 | |
19+
parse-args.js | 98.47 | 53.85 | 100 | 98.47 | 107,108 |
20+
report.js | 96.05 | 70.37 | 100 | 96.05 |... 10,136,137,138 |
21+
lib/commands | 97.73 | 84.21 | 87.5 | 97.73 | |
2222
check-coverage.js | 100 | 92.86 | 100 | 100 | 17 |
23-
report.js | 92.31 | 60 | 50 | 92.31 | 9,10 |
23+
report.js | 92.59 | 60 | 50 | 92.59 | 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.46%) does not meet global threshold (101%)
30+
,ERROR: Coverage for lines (95.55%) does not meet global threshold (101%)
3131
"
3232
`;
3333

3434
exports[`c8 check-coverage allows threshold to be applied on per-file basis 1`] = `
35-
",,ERROR: Coverage for lines (78.33%) does not meet threshold (80%) for lib/commands/check-coverage.js
35+
",,ERROR: Coverage for lines (78.69%) does not meet threshold (80%) for lib/commands/check-coverage.js
3636
ERROR: Coverage for lines (76%) does not meet threshold (80%) for test/fixtures/normal.js
3737
"
3838
`;
3939

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 (95.03%) does not meet global threshold (101%)
43+
",,ERROR: Coverage for lines (95.13%) 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.67 | 68.18 | 74.07 | 84.67 | |
55+
All files | 84.75 | 68.18 | 74.07 | 84.75 | |
5656
bin | 85.71 | 66.67 | 100 | 85.71 | |
5757
c8.js | 85.71 | 66.67 | 100 | 85.71 | 25,32,33,34,35 |
58-
lib | 95.65 | 55.56 | 100 | 95.65 | |
59-
parse-args.js | 96.83 | 41.67 | 100 | 96.83 | 88,89,102,103 |
60-
report.js | 94.67 | 62.5 | 100 | 94.67 |... 08,134,135,136 |
61-
lib/commands | 44.19 | 71.43 | 16.67 | 44.19 | |
62-
check-coverage.js | 23.33 | 100 | 0 | 23.33 |... 55,56,57,58,59 |
63-
report.js | 92.31 | 60 | 50 | 92.31 | 9,10 |
58+
lib | 95.76 | 55.56 | 100 | 95.76 | |
59+
parse-args.js | 96.95 | 41.67 | 100 | 96.95 | 93,94,107,108 |
60+
report.js | 94.74 | 62.5 | 100 | 94.74 |... 10,136,137,138 |
61+
lib/commands | 44.32 | 71.43 | 16.67 | 44.32 | |
62+
check-coverage.js | 22.95 | 100 | 0 | 22.95 |... 56,57,58,59,60 |
63+
report.js | 92.59 | 60 | 50 | 92.59 | 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 | |
@@ -74,15 +74,15 @@ exports[`c8 report generates report from existing temporary files 1`] = `
7474
",--------------------|----------|----------|----------|----------|-------------------|
7575
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
7676
--------------------|----------|----------|----------|----------|-------------------|
77-
All files | 95.46 | 79.76 | 89.66 | 95.46 | |
77+
All files | 95.55 | 79.76 | 89.66 | 95.55 | |
7878
bin | 85.71 | 85.71 | 100 | 85.71 | |
7979
c8.js | 85.71 | 85.71 | 100 | 85.71 | 25,32,33,34,35 |
80-
lib | 97.1 | 69.05 | 100 | 97.1 | |
81-
parse-args.js | 98.41 | 53.85 | 100 | 98.41 | 102,103 |
82-
report.js | 96 | 75.86 | 100 | 96 |... 08,134,135,136 |
83-
lib/commands | 97.67 | 88.89 | 87.5 | 97.67 | |
80+
lib | 97.17 | 69.05 | 100 | 97.17 | |
81+
parse-args.js | 98.47 | 53.85 | 100 | 98.47 | 107,108 |
82+
report.js | 96.05 | 75.86 | 100 | 96.05 |... 10,136,137,138 |
83+
lib/commands | 97.73 | 88.89 | 87.5 | 97.73 | |
8484
check-coverage.js | 100 | 92.31 | 100 | 100 | 17 |
85-
report.js | 92.31 | 80 | 50 | 92.31 | 9,10 |
85+
report.js | 92.59 | 80 | 50 | 92.59 | 9,10 |
8686
test/fixtures | 90.91 | 94.12 | 75 | 90.91 | |
8787
async.js | 100 | 100 | 100 | 100 | |
8888
multiple-spawn.js | 100 | 100 | 100 | 100 | |
@@ -96,12 +96,12 @@ exports[`c8 report supports --check-coverage, when generating reports 1`] = `
9696
",--------------------|----------|----------|----------|----------|-------------------|
9797
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
9898
--------------------|----------|----------|----------|----------|-------------------|
99-
All files | 95.9 | 79.76 | 93.1 | 95.9 | |
99+
All files | 95.97 | 79.76 | 93.1 | 95.97 | |
100100
bin | 85.71 | 83.33 | 100 | 85.71 | |
101101
c8.js | 85.71 | 83.33 | 100 | 85.71 | 25,32,33,34,35 |
102-
lib | 97.1 | 69.05 | 100 | 97.1 | |
103-
parse-args.js | 98.41 | 53.85 | 100 | 98.41 | 102,103 |
104-
report.js | 96 | 75.86 | 100 | 96 |... 08,134,135,136 |
102+
lib | 97.17 | 69.05 | 100 | 97.17 | |
103+
parse-args.js | 98.47 | 53.85 | 100 | 98.47 | 107,108 |
104+
report.js | 96.05 | 75.86 | 100 | 96.05 |... 10,136,137,138 |
105105
lib/commands | 100 | 89.47 | 100 | 100 | |
106106
check-coverage.js | 100 | 92.31 | 100 | 100 | 17 |
107107
report.js | 100 | 83.33 | 100 | 100 | 16 |
@@ -111,7 +111,7 @@ All files | 95.9 | 79.76 | 93.1 | 95.9 |
111111
normal.js | 76 | 75 | 33.33 | 76 | 14,15,16,18,19,20 |
112112
subprocess.js | 100 | 100 | 100 | 100 | |
113113
--------------------|----------|----------|----------|----------|-------------------|
114-
,ERROR: Coverage for lines (95.9%) does not meet global threshold (101%)
114+
,ERROR: Coverage for lines (95.97%) does not meet global threshold (101%)
115115
"
116116
`;
117117

0 commit comments

Comments
 (0)