-
-
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
Code coverage is missing when using projects, if each project's rootDir is not set to the root rootDir's value #5417
Comments
The second workaround of setting rootDir actually messes with a bunch of other things (e.g. you need to be careful to specify exact testRegexes, otherwise it starts matching elsewhere, the .babelrc-based transforms stop working, etc.), so it's not really an option. |
Run jest with let packages = getThePathsOfMyProjects(); // ['./packages/client', './packages/server' ..]
const projectConfigs = packages.map(packagePath => ({
roots: [packagePath],
rootDir: 'whatever I set it will be overwritten',
testEnvironment: 'node',
testMatch: ['**/test/**/*.js?(x)'],
...
}));
module.exports = {
projects: projectConfigs,
collectCoverageFrom: ['packages/**/*.{js,jsx}'],
...
}; |
@dioklecijan I've tried this and can't get it to work for the life of me. If I put |
I feel like there is something off with |
Related: I've found that using jest.config.js
jest-custom-project.config.js
You need to configure |
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 30 days. |
Any changes ? |
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 30 days. |
comment |
+1 |
Do you want to request a feature or report a bug?
A bug.
What is the current behavior?
When you're using Jest with projects and you want to collect coverage across them, following this advice #4255 (comment) does not give you coverage. You still need to set each project's rootDir setting to the root root, e.g.
"../"
(https://github.com/adaniliuk/jest-projects-config-issue/blob/master/client/jest.config.js#L4).If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can
yarn install
andyarn test
.You can see it here. https://github.com/jure/jest-projects-config-issue. The current result is:
If you were to add rootDir
../../
to each project, and adjust the configs accordingly, it would work OK.What is the expected behavior?
Configuring a global coverage config (e.g. here https://github.com/jure/jest-projects-config-issue/blob/master/jest.config.js#L6) should use the global
rootDir
(which is also the context of the config at that point), when matching files for instrumentation here: https://github.com/facebook/jest/blob/9afeb9c757e4b92dbf670e66545dce3df5c407c4/packages/jest-runtime/src/should_instrument.js#L59-L69.As it is, the match is done against the relative path, where rootDir is the rootDir of each project, e.g.
This means that, for example, the global pattern
'packages/server/**/*.{js,jsx}'
won't match.Possible workarounds
It's possible to specify global coverage patterns in their relative form, e.g.
'*.js'
, but those are too generic and match too much compared to their specific alternatives.As mentioned above, one can specify rootDir to be the global rootDir in each package, and adjust all config accordingly. This seems like more of a hack than a workable solution.
Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.
Jest 22.1.4, Node.js 9.4.0, macOS 10.12.6
The text was updated successfully, but these errors were encountered: