Tests from different monorepo package are ignored in coverage
See original GitHub issueš Bug Report
I have a monorepo, and some tests are in a separate package.
packages/
package-a/
package-b/
tests/
I have a root ject.config.js
with projects set to an array of specific packages as <rootDir>/packages/package-X/
items, and every package has its own jest.config.js
with some overrides. Tests work from the root and from an individual package.
Tests in packages/tests
import files from another packages by their name like import { } from '@user/package-a/src/utils.js';
. Those tests present in Jest output and are green, but missing in coverage output.
If I add an explicit collectCoverageFrom: [ '**/*.js' ]
then I can see those files in coverage having 0%.
Changing an import to a path like import { } from '../../package-a/src/utils.js';
has no effect. Removing node_modules
from coveragePathIgnorePatterns
doesnāt help too.
When I run tests from the packages/tests
with --coverage
option, all tests in this package are green, but the coverage table is empty.
Adding <rootDir>
item to the projects
emits right coverage, but runs tests in some packages that it shouldnāt (that why projects have not all packages listed).
To Reproduce
Steps to reproduce the behavior: Run Jest from the root in such monorepo configuration, there will be no coverage.
Expected behavior
Coverage should work as if imports are by path.
Link to repl or repo (highly encouraged)
yarn
yarn test --coverage
Tests from packages/undercut-tests
donāt count for coverage of packages/undercut-pull
.
envinfo
$ npx envinfo --preset jest
npx: installed 1 in 1.146s
System:
OS: Linux 5.3 Ubuntu 19.10 (Eoan Ermine)
CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
npmPackages:
jest: ^24.9.0 => 24.9.0
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:5 (3 by maintainers)
Top GitHub Comments
I was able to reproduce in a smaller example here https://github.com/pveyes/jest-multi-project-monorepo-coverage-bug. I found out that using
projects
field causes this bug. If you donāt use multi project, it works fineIām currently working around it by using a combination of
roots
and custom glob forcollectCoverageFrom
based on whatās currently being tested.I am having the following monorepo structure
My jest config
but it seems to be skipping bar. The only difference I can spot between bar and others is that it contains ts files only. However the directory structure is as per the glob mentioned above.
Can anyone tell me how to troubleshoot this?