-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Inconsistent output with --coverage #7176
Comments
IMO the second case should include |
@bcoe could you help out here? Is it possible to change the base reporting directory? I found https://github.com/gotwarlost/istanbul/blob/bc84c315271a5dd4d39bcefc5925cfb61a3d174a/lib/util/file-matcher.js, but setting a breakpoint in it doesn't seem to change anything. I tried this, makes no difference: diff --git i/packages/jest-cli/src/reporters/coverage_reporter.js w/packages/jest-cli/src/reporters/coverage_reporter.js
index 7d3fffe2a..9711378b5 100644
--- i/packages/jest-cli/src/reporters/coverage_reporter.js
+++ w/packages/jest-cli/src/reporters/coverage_reporter.js
@@ -21,7 +21,7 @@ import type {Context} from 'types/Context';
import type {Test} from 'types/TestRunner';
import {clearLine, isInteractive} from 'jest-util';
-import {createReporter} from 'istanbul-api';
+import {config as istanbulConfig, createReporter} from 'istanbul-api';
import chalk from 'chalk';
import istanbulCoverage from 'istanbul-lib-coverage';
import libSourceMaps from 'istanbul-lib-source-maps';
@@ -87,7 +87,12 @@ export default class CoverageReporter extends BaseReporter {
this._coverageMap,
);
- const reporter = createReporter();
+ // TODO: Figure out the common base of all of them
+ const root = Array.from(contexts)[0].config.rootDir;
+
+ const cfg = istanbulConfig.loadFile(null, {instrumentation: {root}});
+
+ const reporter = createReporter(cfg);
try {
if (this._globalConfig.coverageDirectory) {
reporter.dir = this._globalConfig.coverageDirectory; |
The reporter is |
@coreyfarrell thoughts on this one? |
Probably would make sense to report relative to the detected/declared project root and also label that as "Project Root" instead of naming the FS directory. That said it's been this way forever and people tend to be pretty sensitive to reporting changes so I'm not sure I'd want to change this in a semver-minor. I'm otherwise occupied currently, it would help me if someone posted a bug to github.com/istanbuljs/istanbuljs/ and link to this issue. |
In my opinion I don’t see this as a bug. The coverage will always report relative to the folder containing the topmost reported coverage, not related to the current working directory as initially reported. |
I agree it's not a bug in that it behaves as intended - I do think the behavior is not ideal, though. I think we should be able to set a root, and that all paths should be relative to that regardless of what istanbul considers "top of the tree". If I do I can open up an issue tomorrow 👍 |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days. |
👋 bringing this thread back to life, would happily take a patch to istanbuljs/istanbuljs to make this configurable. |
That'd be awesome! Do you have any pointers to where we would make changes so a |
@SimenB I can dig a little bit tomorrow, I'm honestly not too sure. If you could figure out how to provide a minimal example in a repo of behavior that has the wrong root, it would help me dig. |
I would assume the repository in the OP still reproduces? Should update jest to latest to ensure we're using the latest versions of istanbul etc, but beyond that it should be fine? |
@SimenB does the issue in |
probably not, not exactly minimal. Just updating the one in the OP to latest Jest should be enough tho (unless @bcoe wants a version without Jest at all) |
I was able to reproduce this with the original repo after upgrading to jest v28. I've also been able to create a even smaller reproduction that doesn't use It has two coverage maps that were generated from the original reproduction repo just with no code in the If you call
If you call
The desired behaviour (which this issue is about) is that both of these coverage reports should have |
Awesome! Yeah, or at least if passed some sort of |
🐛 Bug Report
When code-covered files exist in the root directory, the
--coverage
output will include the name of the directory. This is not desirable in CI scenarios where the working directory will vary.Actual
https://github.com/azz/jest-istanbul-issue/tree/master
When a file exists at root (above), the output is:
Note the
jest-istanbul-issue
above.Expected
https://github.com/azz/jest-istanbul-issue/tree/good-case
When it doesn't:
The text was updated successfully, but these errors were encountered: