Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --projectRoot option #415

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/commands/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ exports.outputReport = async function (argv) {
allowExternal: argv.allowExternal,
src: argv.src,
skipFull: argv.skipFull,
excludeNodeModules: argv.excludeNodeModules
excludeNodeModules: argv.excludeNodeModules,
projectRoot: argv.projectRoot
})
await report.run()
if (argv.checkCoverage) await checkCoverages(argv, report)
Expand Down
5 changes: 5 additions & 0 deletions lib/parse-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ function buildYargs (withCommands = false) {
describe: 'supplying --allowExternal will cause c8 to allow files from outside of your cwd. This applies both to ' +
'files discovered in coverage temp files and also src files discovered if using the --all flag.'
})
.options('project-root', {
default: undefined,
type: 'string',
describe: 'specifies which points point to the root of the mono repository'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this option overlaps with the undocumented resolve option. Have you tried using it as the projectRoot in istanbul-reporter options?

projectRoot: this.resolve || process.cwd(),

With the current changes it feels like you'd need to keep projectRoot and resolve in sync manually.

c8/lib/parse-args.js

Lines 136 to 139 in 7f1069d

.option('resolve', {
default: '',
describe: 'resolve paths to alternate base directory'
})

const path = resolve(this.resolve, v8ScriptCov.url)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I don't understand why the 'resolve' option is needed. Whatever I specify there, it does not affect the final files.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried using this, but it didn't help me.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

projectRoot only affects paths in lcov files. We are currently using a fork in a working project and it works fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some testing with the this.resolve option now, and it indeed seems to have no effect at all. The v8ScriptCov.url paths are absolute, not relative. No idea what that API is supposed to do.

})
.pkgConf('c8')
.demandCommand(1)
.check((argv) => {
Expand Down
7 changes: 5 additions & 2 deletions lib/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class Report {
src,
allowExternal = false,
skipFull,
excludeNodeModules
excludeNodeModules,
projectRoot
}) {
this.reporter = reporter
this.reportsDirectory = reportsDirectory
Expand All @@ -51,6 +52,7 @@ class Report {
this.all = all
this.src = this._getSrc(src)
this.skipFull = skipFull
this.projectRoot = projectRoot
}

_getSrc (src) {
Expand All @@ -74,7 +76,8 @@ class Report {
reports.create(_reporter, {
skipEmpty: false,
skipFull: this.skipFull,
maxCols: process.stdout.columns || 100
maxCols: process.stdout.columns || 100,
projectRoot: this.projectRoot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rasimx looks like an alternative way to pass this option was implemented in #423.

It's included in c8@7.13.0.

}).execute(context)
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "c8",
"version": "7.12.0",
"version": "7.13.0",
"description": "output coverage reports using Node.js' built in coverage",
"main": "./index.js",
"types": "./index.d.ts",
Expand Down
8 changes: 4 additions & 4 deletions test/integration.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ hey
---------------------------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---------------------------------------|---------|----------|---------|---------|-------------------
All files | 1.91 | 12 | 6.25 | 1.91 |
All files | 1.9 | 12 | 6.25 | 1.9 |
c8 | 0 | 0 | 0 | 0 |
index.js | 0 | 0 | 0 | 0 | 1
c8/bin | 0 | 0 | 0 | 0 |
Expand All @@ -167,12 +167,12 @@ All files | 1.91 | 12 | 6.25 | 1.91
sorter.js | 0 | 0 | 0 | 0 | 1-196
c8/lib | 0 | 0 | 0 | 0 |
is-cjs-esm-bridge.js | 0 | 0 | 0 | 0 | 1-10
parse-args.js | 0 | 0 | 0 | 0 | 1-218
report.js | 0 | 0 | 0 | 0 | 1-337
parse-args.js | 0 | 0 | 0 | 0 | 1-223
report.js | 0 | 0 | 0 | 0 | 1-340
source-map-from-file.js | 0 | 0 | 0 | 0 | 1-100
c8/lib/commands | 0 | 0 | 0 | 0 |
check-coverage.js | 0 | 0 | 0 | 0 | 1-70
report.js | 0 | 0 | 0 | 0 | 1-41
report.js | 0 | 0 | 0 | 0 | 1-42
c8/test/fixtures | 15.95 | 35.29 | 20 | 15.95 |
async.js | 100 | 100 | 100 | 100 |
c8-ignore-next.js | 0 | 0 | 0 | 0 | 1-22
Expand Down
70 changes: 35 additions & 35 deletions test/integration.js_10.snap
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ hey
---------------------------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---------------------------------------|---------|----------|---------|---------|-------------------
All files | 1.91 | 12 | 8.16 | 1.91 |
All files | 1.9 | 12 | 8.16 | 1.9 |
c8 | 0 | 0 | 0 | 0 |
index.js | 0 | 0 | 0 | 0 | 1
c8/bin | 0 | 0 | 0 | 0 |
Expand All @@ -167,12 +167,12 @@ All files | 1.91 | 12 | 8.16 | 1.91
sorter.js | 0 | 0 | 0 | 0 | 1-196
c8/lib | 0 | 0 | 0 | 0 |
is-cjs-esm-bridge.js | 0 | 0 | 0 | 0 | 1-10
parse-args.js | 0 | 0 | 0 | 0 | 1-218
report.js | 0 | 0 | 0 | 0 | 1-337
parse-args.js | 0 | 0 | 0 | 0 | 1-223
report.js | 0 | 0 | 0 | 0 | 1-340
source-map-from-file.js | 0 | 0 | 0 | 0 | 1-100
c8/lib/commands | 0 | 0 | 0 | 0 |
check-coverage.js | 0 | 0 | 0 | 0 | 1-70
report.js | 0 | 0 | 0 | 0 | 1-41
report.js | 0 | 0 | 0 | 0 | 1-42
c8/test/fixtures | 15.95 | 35.29 | 25 | 15.95 |
async.js | 100 | 100 | 100 | 100 |
c8-ignore-next.js | 0 | 0 | 0 | 0 | 1-22
Expand Down Expand Up @@ -257,24 +257,24 @@ hey
--------------------------|---------|----------|---------|---------|--------------------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------------------|---------|----------|---------|---------|--------------------------------
All files | 73.95 | 58.82 | 63.41 | 73.95 |
All files | 74.22 | 58.82 | 63.41 | 74.22 |
bin | 78.84 | 60 | 66.66 | 78.84 |
c8.js | 78.84 | 60 | 66.66 | 78.84 | 22,27-29,32-33,41-43,50-51
lib | 78.49 | 54.23 | 73.07 | 78.49 |
lib | 78.75 | 54.23 | 73.07 | 78.75 |
is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9
parse-args.js | 97.24 | 58.33 | 100 | 97.24 | 159-160,181-182,195-196
report.js | 75.96 | 57.89 | 80 | 75.96 | ...281,287-289,310-315,326-327
parse-args.js | 97.3 | 58.33 | 100 | 97.3 | 164-165,186-187,200-201
report.js | 76.17 | 57.89 | 80 | 76.17 | ...284,290-292,313-318,329-330
source-map-from-file.js | 45 | 100 | 0 | 45 | 39-50,52-67,69-77,81-98
lib/commands | 41.44 | 66.66 | 16.66 | 41.44 |
lib/commands | 41.96 | 66.66 | 16.66 | 41.96 |
check-coverage.js | 18.57 | 100 | 0 | 18.57 | 9-11,14-36,39-53,55-70
report.js | 80.48 | 62.5 | 50 | 80.48 | 9-10,15-20
report.js | 80.95 | 62.5 | 50 | 80.95 | 9-10,15-20
test/fixtures | 83.33 | 85.71 | 66.66 | 83.33 |
async.js | 100 | 100 | 100 | 100 |
normal.js | 75 | 66.66 | 33.33 | 75 | 14-16,18-20
--------------------------|---------|----------|---------|---------|--------------------------------
,ERROR: Coverage for lines (73.95%) does not meet global threshold (101%)
,ERROR: Coverage for lines (74.22%) does not meet global threshold (101%)
ERROR: Coverage for branches (58.82%) does not meet global threshold (82%)
ERROR: Coverage for statements (73.95%) does not meet global threshold (95%)
ERROR: Coverage for statements (74.22%) does not meet global threshold (95%)
"
`;

Expand All @@ -284,17 +284,17 @@ ERROR: Coverage for branches (60%) does not meet threshold (82%) for bin/c8.js
ERROR: Coverage for statements (78.84%) does not meet threshold (95%) for bin/c8.js
ERROR: Coverage for lines (18.57%) does not meet threshold (101%) for lib/commands/check-coverage.js
ERROR: Coverage for statements (18.57%) does not meet threshold (95%) for lib/commands/check-coverage.js
ERROR: Coverage for lines (80.48%) does not meet threshold (101%) for lib/commands/report.js
ERROR: Coverage for lines (80.95%) does not meet threshold (101%) for lib/commands/report.js
ERROR: Coverage for branches (62.5%) does not meet threshold (82%) for lib/commands/report.js
ERROR: Coverage for statements (80.48%) does not meet threshold (95%) for lib/commands/report.js
ERROR: Coverage for statements (80.95%) does not meet threshold (95%) for lib/commands/report.js
ERROR: Coverage for lines (90%) does not meet threshold (101%) for lib/is-cjs-esm-bridge.js
ERROR: Coverage for branches (25%) does not meet threshold (82%) for lib/is-cjs-esm-bridge.js
ERROR: Coverage for statements (90%) does not meet threshold (95%) for lib/is-cjs-esm-bridge.js
ERROR: Coverage for lines (97.24%) does not meet threshold (101%) for lib/parse-args.js
ERROR: Coverage for lines (97.3%) does not meet threshold (101%) for lib/parse-args.js
ERROR: Coverage for branches (58.33%) does not meet threshold (82%) for lib/parse-args.js
ERROR: Coverage for lines (75.96%) does not meet threshold (101%) for lib/report.js
ERROR: Coverage for lines (76.17%) does not meet threshold (101%) for lib/report.js
ERROR: Coverage for branches (57.89%) does not meet threshold (82%) for lib/report.js
ERROR: Coverage for statements (75.96%) does not meet threshold (95%) for lib/report.js
ERROR: Coverage for statements (76.17%) does not meet threshold (95%) for lib/report.js
ERROR: Coverage for lines (45%) does not meet threshold (101%) for lib/source-map-from-file.js
ERROR: Coverage for statements (45%) does not meet threshold (95%) for lib/source-map-from-file.js
ERROR: Coverage for lines (100%) does not meet threshold (101%) for test/fixtures/async.js
Expand All @@ -305,19 +305,19 @@ ERROR: Coverage for statements (75%) does not meet threshold (95%) for test/fixt
`;

exports[`c8 check-coverage check-coverage command with --100 1`] = `
",,ERROR: Coverage for lines (77.66%) does not meet global threshold (100%)
",,ERROR: Coverage for lines (77.89%) does not meet global threshold (100%)
ERROR: Coverage for functions (67.44%) does not meet global threshold (100%)
ERROR: Coverage for branches (62.06%) does not meet global threshold (100%)
ERROR: Coverage for statements (77.66%) does not meet global threshold (100%)
ERROR: Coverage for statements (77.89%) does not meet global threshold (100%)
"
`;

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 (73.95%) does not meet global threshold (101%)
",,ERROR: Coverage for lines (74.22%) does not meet global threshold (101%)
ERROR: Coverage for branches (58.82%) does not meet global threshold (82%)
ERROR: Coverage for statements (73.95%) does not meet global threshold (95%)
ERROR: Coverage for statements (74.22%) does not meet global threshold (95%)
"
`;

Expand Down Expand Up @@ -404,17 +404,17 @@ exports[`c8 report generates report from existing temporary files 1`] = `
",--------------------------|---------|----------|---------|---------|--------------------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------------------|---------|----------|---------|---------|--------------------------------
All files | 73.95 | 58.82 | 63.41 | 73.95 |
All files | 74.22 | 58.82 | 63.41 | 74.22 |
bin | 78.84 | 60 | 66.66 | 78.84 |
c8.js | 78.84 | 60 | 66.66 | 78.84 | 22,27-29,32-33,41-43,50-51
lib | 78.49 | 54.23 | 73.07 | 78.49 |
lib | 78.75 | 54.23 | 73.07 | 78.75 |
is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9
parse-args.js | 97.24 | 58.33 | 100 | 97.24 | 159-160,181-182,195-196
report.js | 75.96 | 57.89 | 80 | 75.96 | ...281,287-289,310-315,326-327
parse-args.js | 97.3 | 58.33 | 100 | 97.3 | 164-165,186-187,200-201
report.js | 76.17 | 57.89 | 80 | 76.17 | ...284,290-292,313-318,329-330
source-map-from-file.js | 45 | 100 | 0 | 45 | 39-50,52-67,69-77,81-98
lib/commands | 41.44 | 66.66 | 16.66 | 41.44 |
lib/commands | 41.96 | 66.66 | 16.66 | 41.96 |
check-coverage.js | 18.57 | 100 | 0 | 18.57 | 9-11,14-36,39-53,55-70
report.js | 80.48 | 62.5 | 50 | 80.48 | 9-10,15-20
report.js | 80.95 | 62.5 | 50 | 80.95 | 9-10,15-20
test/fixtures | 83.33 | 85.71 | 66.66 | 83.33 |
async.js | 100 | 100 | 100 | 100 |
normal.js | 75 | 66.66 | 33.33 | 75 | 14-16,18-20
Expand All @@ -426,24 +426,24 @@ exports[`c8 report supports --check-coverage, when generating reports 1`] = `
",--------------------------|---------|----------|---------|---------|--------------------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------------------|---------|----------|---------|---------|--------------------------------
All files | 73.95 | 58.82 | 63.41 | 73.95 |
All files | 74.22 | 58.82 | 63.41 | 74.22 |
bin | 78.84 | 60 | 66.66 | 78.84 |
c8.js | 78.84 | 60 | 66.66 | 78.84 | 22,27-29,32-33,41-43,50-51
lib | 78.49 | 54.23 | 73.07 | 78.49 |
lib | 78.75 | 54.23 | 73.07 | 78.75 |
is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9
parse-args.js | 97.24 | 58.33 | 100 | 97.24 | 159-160,181-182,195-196
report.js | 75.96 | 57.89 | 80 | 75.96 | ...281,287-289,310-315,326-327
parse-args.js | 97.3 | 58.33 | 100 | 97.3 | 164-165,186-187,200-201
report.js | 76.17 | 57.89 | 80 | 76.17 | ...284,290-292,313-318,329-330
source-map-from-file.js | 45 | 100 | 0 | 45 | 39-50,52-67,69-77,81-98
lib/commands | 41.44 | 66.66 | 16.66 | 41.44 |
lib/commands | 41.96 | 66.66 | 16.66 | 41.96 |
check-coverage.js | 18.57 | 100 | 0 | 18.57 | 9-11,14-36,39-53,55-70
report.js | 80.48 | 62.5 | 50 | 80.48 | 9-10,15-20
report.js | 80.95 | 62.5 | 50 | 80.95 | 9-10,15-20
test/fixtures | 83.33 | 85.71 | 66.66 | 83.33 |
async.js | 100 | 100 | 100 | 100 |
normal.js | 75 | 66.66 | 33.33 | 75 | 14-16,18-20
--------------------------|---------|----------|---------|---------|--------------------------------
,ERROR: Coverage for lines (73.95%) does not meet global threshold (101%)
,ERROR: Coverage for lines (74.22%) does not meet global threshold (101%)
ERROR: Coverage for branches (58.82%) does not meet global threshold (82%)
ERROR: Coverage for statements (73.95%) does not meet global threshold (95%)
ERROR: Coverage for statements (74.22%) does not meet global threshold (95%)
"
`;

Expand Down