question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

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)

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 

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:6
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pveyescommented, 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.

0reactions
raul1991commented, Jul 18, 2022

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Aggregating Unit Test Coverage for All Monorepo's Packages
In this post join me as I will be adding an aggregated unit test code coverage report for my Pedalboard monorepo. Monorepos contain...
Read more >
jest coverageDirectory configuration for project inside monorepo
You can only specify a different coverage directory for each project if you are running jest for each product individually.
Read more >
Flags - Codecov
Flags allow you to isolate and categorize coverage reports for different tests and features in your project. This is particularly helpful if:.
Read more >
Configuring Jest compiled - w3resource
Jest's configuration can be defined inside the package.json file of ... Test files will normally be ignored from collecting code coverage.
Read more >
Configuring Jest
Jest will run .mjs and .js files with nearest package.json 's type field set to module as ... Test files are normally ignored...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found