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

Tests from different monorepo package are ignored in coverage #9323

Closed
the-spyke opened this issue Dec 18, 2019 · 8 comments
Closed

Tests from different monorepo package are ignored in coverage #9323

the-spyke opened this issue Dec 18, 2019 · 8 comments

Comments

@the-spyke
Copy link
Contributor

the-spyke commented Dec 18, 2019

🐛 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)

Repo

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 
@the-spyke the-spyke changed the title Tests with monorepo package imports are ignored in coverage Tests from different monorepo package are ignored in coverage Dec 18, 2019
@the-spyke
Copy link
Contributor Author

I've added a link to the repo. Jest 25 -- same behavior.

@the-spyke
Copy link
Contributor Author

Jest 26 doesn't solve the issue:

git clone https://github.com/the-spyke/undercut
cd undercut
yarn
yarn test --coverage

@pveyes
Copy link

pveyes commented Mar 10, 2021

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 fine

I'm currently working around it by using a combination of roots and custom glob for collectCoverageFrom based on what's currently being tested.

@AndrewSouthpaw
Copy link
Contributor

@pveyes could you share what your workaround with roots looks like? We're running into this issue currently, I had no idea that cross-module coverage would be ignored. We're currently using projects, like so:

jest.base.config.js // each module config pulls this in and adds customization
modules
|__ a
    |__ jest.config.js
|__ b
    |__ jest.config.js

@raul1991
Copy link

I am having the following monorepo structure

|___packages
         |_________ foo
         |_________ bar
         |_________ more

My jest config

--collectCoverageFrom=\"<rootDir>/packages/**/src/**/*.(js|ts|tsx)\"

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?

@github-actions
Copy link

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.

@github-actions github-actions bot added the Stale label Jul 18, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 17, 2023
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants