Do you want to request a feature or report a bug?
Bug
What is the current behavior?
jest v20 allows running tests in parallel for different projects with --projects param. Unfortunately, if this is done for 2 projects with different code coverage settings, coverage is calculated only for the 1st one. It seems like second project code coverage settings are not picked up at all.
If tests are executed for each project separately, then coverage is calculated correctly.
I've created a small repo to reproduce the issue https://github.com/adaniliuk/jest-projects-config-issue/
What is the expected behavior?
Code coverage is calculated independently for each project.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
jest v20.0.4
node v7.10.0
yarn v0.24.6
Mac OS X v10.12.6
this is actually expected (although not perfect) right now due to some of our design decisions.
since coverage is reported from the master process, it can't be configured per project.
another thing that we have is that if you don't provide a globalConfig option, global config values will be taken from the first project you pass (client in your case).
there isn't really much we can do right now without changing most of the multi-project runner design, and honestly i haven't tested coverage generating with MPR yet, i'm pretty sure we have a lot of bugs there :(
what you can do to make it work right now is:
globalConfig that will have coverage and project info:// ./jest.config.js
module.exports = {
collectCoverageFrom: [...], // configuration values for **both** projects
projects: ['./client', './server'],
};
jest --config ./jest-config.jsyou can look at this test as an example https://github.com/facebook/jest/blob/master/integration_tests/__tests__/multi_project_runner.test.js#L42-L91
@aaronabramov thanks for your answer, but it seems like projects property in ./jest.config.js is not taken into account at all. The only way to specify project is to add them to cli command, but then if global config is specified projects configs are not considered.
$ jest --projects ./client ./server - projects individual configs are used, root is not used
$ jest --projects ./client ./server --config ./jest.config.js - root config is used only
$ jest --config ./jest.config.js - root config is used only
hm.. ok that seems like a bug. Since we have a test case that tests the projects property in global config it seems like it's related to your specific project. Do you mind opening another issue for it? i'll look into it (probably next week)
@aaronabramov seems like there is already one https://github.com/facebook/jest/issues/3718
It looks the same, right? Or not? If not I'll open another one.
Can you try jest@test release?
@thymikee great, the solution proposed by @aaronabramov works with jest@test release. Thank you very much.
I've updated https://github.com/adaniliuk/jest-projects-config-issue/ with the solution and jest@test release version.
@thymikee could you let me know when this change will be included in the release version?
@thymikee @aaronabramov thank you again, this will simplify our jest config and npm tasks a lot.
@aaronabramov Is this still the case, i.e. do you need to specify collectCoverageFrom globally? Can't find much documentation about it (other than this issue, really). I'm having various issues with this (Running with --projects x y z e.g. produces coverage, but it's weird and missing, while setting the collectCoverageFrom globally produces no coverage info (just Unknown for all columns).
Adding these two configs will work for me.
"collectCoverage": true,
"collectCoverageFrom": ["/src//*/!(.spec).js"]
Most helpful comment
@aaronabramov Is this still the case, i.e. do you need to specify
collectCoverageFromglobally? Can't find much documentation about it (other than this issue, really). I'm having various issues with this (Running with--projects x y ze.g. produces coverage, but it's weird and missing, while setting thecollectCoverageFromglobally produces no coverage info (just Unknown for all columns).