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

Coverage incomplete using projects #5457

Closed
robdonn opened this issue Feb 4, 2018 · 23 comments
Closed

Coverage incomplete using projects #5457

robdonn opened this issue Feb 4, 2018 · 23 comments

Comments

@robdonn
Copy link

robdonn commented Feb 4, 2018

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

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 and yarn test.

  • All tests run with their correct configuration
  • A single coverage report is created at project root but the coverage is not complete
    • products/product-2 root index.js does not receive coverage, although the test covers it

Sample repo

--------------------------------|----------|----------|----------|----------|----------------|
File                            |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
--------------------------------|----------|----------|----------|----------|----------------|
All files                       |    85.71 |      100 |      100 |    85.71 |                |
 packages/package-1/src         |      100 |      100 |      100 |      100 |                |
  index.js                      |      100 |      100 |      100 |      100 |                |
 packages/package-1/src/example |      100 |      100 |      100 |      100 |                |
  index.js                      |      100 |      100 |      100 |      100 |                |
 packages/package-2             |      100 |      100 |      100 |      100 |                |
  index.js                      |      100 |      100 |      100 |      100 |                |
 packages/package-2/sample      |      100 |      100 |      100 |      100 |                |
  index.js                      |      100 |      100 |      100 |      100 |                |
 products/product-1             |      100 |      100 |      100 |      100 |                |
  index.js                      |      100 |      100 |      100 |      100 |                |
 products/product-1/sample      |      100 |      100 |      100 |      100 |                |
  index.js                      |      100 |      100 |      100 |      100 |                |
 products/product-2             |        0 |      100 |      100 |        0 |                |
  index.js                      |        0 |      100 |      100 |        0 |              1 |
--------------------------------|----------|----------|----------|----------|----------------|

What is the expected behavior?

  • All tests would run with their correct configurations
  • A single coverage report would be created at project root

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

Jest configurations are available in the sample repo. There is a configuration in the root of the repository and configurations also in each project folder for more project-specific stuff.

All coverage configuration is done at root as globalConfig as recommended in #4255

MacOS High Sierra - 10.13.3
node - v9.3.0
yarn -v 1.3.2

@ranyitz
Copy link
Contributor

ranyitz commented Feb 5, 2018

Hey @robdonn
I've tried to recreate the issue locally.

  1. Cloned to your sample project.
  2. Ran yarn
  3. Ran yarn test

Although I have matched versions of node, yarn, and even MacOs High Sierra I could not recreate it.

screen shot 2018-02-06 at 0 29 55

@rileylnapier
Copy link

rileylnapier commented Feb 6, 2018

i have this same problem too and its been driving me nuts.

possibly something to do with multiple packages that depend on each other using lerna? hmmm not sure

@DrewML
Copy link

DrewML commented Jun 20, 2018

Possibly related to #6506

@wldcordeiro
Copy link

Still seeing this issue on latest, seems like repeated runs will eventually pick up the projects for me.

@SimenB
Copy link
Member

SimenB commented Sep 2, 2018

Can someone set up a good reproduction case for this?

@DrewML
Copy link

DrewML commented Sep 4, 2018

@SimenB minimal test case is available in #6506. https://github.com/DrewML/jest-coverage-bug-repro

@nerdmax
Copy link

nerdmax commented Sep 12, 2018

Same issue. It's driving me crazy. We have to depreciate the jest projects settings

@nrobertdehault
Copy link

@nerdmax I'm sure that's not optimal but running all the tests in parallel by passing --maxWorkers=100 fixed the coverage report for me.

@nerdmax
Copy link

nerdmax commented Sep 13, 2018

@nrobertdehault Thank you for your reply. I tried --maxWorkers=100 but still not working 😟. I appreciate your suggestion.

@jure
Copy link

jure commented Oct 16, 2018

For what it's worth, we've had the same problem for a good while, but since we've been using the fix in istanbuljs/babel-plugin-istanbul#171, we're getting coverage on all of our projects in a multi-project Jest... uhm... project. :) As described in the PR above, I believe this is the cause of several multi-project coverage related issues: this one, #5417 and #6483.

Give it a shot!

@SimenB
Copy link
Member

SimenB commented Oct 16, 2018

That's awesome @jure!

@jorgenader
Copy link

Had similar issue with missing coverage in CI. Managed to locally repro this by running jest with --runInBand. Adding --maxWorkers=N fixed the problem in CI.

@panjiesw
Copy link

panjiesw commented Dec 3, 2018

Got bitten by this recently as my test file count grows. The key to reproduce is to have many test files, far exceeding the default number of test workers.

All sample repro to similar issues to this have number of test files less than my cpu core, so I can't reproduce the issue (coverage generated correctly) with it.

My project has 23 test files across 5 sub-projects, running with default worker, the coverage is incomplete like this issue described. But running --maxWorkers 23 the coverage is generated correctly.

--no-cache and --runInBand doesn't make any difference for me.

@jure
Copy link

jure commented Dec 3, 2018

@panjiesw If you're using yarn, can you try using resolutions to do something like

  "resolutions": {
    "babel-plugin-istanbul": "https://github.com/jure/babel-plugin-istanbul.git#temp_release"
  }

The above uses the code from istanbuljs/babel-plugin-istanbul#171, but compiled to lib/index.js. At your own risk etc, but this solved the issues for us and it would be good to get a confirmation.

@panjiesw
Copy link

panjiesw commented Dec 3, 2018

@jure I'm not using yarn. Is there any similar way using npm to resolve babel-plugin-istanbul with your fix?

@SimenB are you still looking for good repro for this issue? There is one linked to this issue, if the author don't mind , which I have tried and also suffer from this issue: https://github.com/magento-research/pwa-studio

@jure
Copy link

jure commented Dec 3, 2018

@panjiesw For a simple one-off test, you could find the babel-plugin-istanbul dependency in your node_modules, and manually copy the contents of lib/index.js from https://github.com/jure/babel-plugin-istanbul/blob/temp_release/lib/index.js into it.

@panjiesw
Copy link

panjiesw commented Dec 3, 2018

@jure got it working using your suggested solution. Can confirm now the coverage generated correctly, it works!

Now we wait until it's released and jest using the new babel-plugin-istanbul

@SimenB
Copy link
Member

SimenB commented Dec 3, 2018

Jest uses v5 of babel-istanbul-plugin in the babel 7 branch (on hold due to another istanbul bug, see #7202). It will be part of Jest 24

@jure
Copy link

jure commented Dec 3, 2018

Just a heads up, the babel-plugin-istanbul that fixes the discussed issue hasn't been released yet, but the fix is merged to master.

@SimenB
Copy link
Member

SimenB commented Jan 11, 2019

@DrewML your reproduction is fixed in Jest 24 (using babel-plugin-istanbul@5.1.0).

$ npx jest --version
24.0.0-alpha.12
$ npm run test:ohno

> jest-coverage-bug-repro@1.0.0 test:ohno /Users/simen/Development/jest-coverage-bug-repro
> jest --no-cache -i

 PASS   Project 1  packages/project1/index.spec.js
 PASS   Project 2  packages/project2/index.spec.js
-----------|----------|----------|----------|----------|-------------------|
File       |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
-----------|----------|----------|----------|----------|-------------------|
All files  |      100 |      100 |      100 |      100 |                   |
 project1  |      100 |      100 |      100 |      100 |                   |
  index.js |      100 |      100 |      100 |      100 |                   |
 project2  |      100 |      100 |      100 |      100 |                   |
  index.js |      100 |      100 |      100 |      100 |                   |
-----------|----------|----------|----------|----------|-------------------|

Test Suites: 2 passed, 2 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        3.728s
Ran all test suites in 2 projects.

Gonna close, trying to find a reproduction to test the fix in babel-plugin-istanbul 😅

@SimenB SimenB closed this as completed Jan 11, 2019
@DrewML
Copy link

DrewML commented Jan 30, 2019

Awesome - thanks @SimenB! Much appreciated.

@aj-anuragjain
Copy link

Adding these two configs will work for me.

"collectCoverage": true,
"collectCoverageFrom": ["/src//**/!(*.spec).js"]

@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 May 11, 2021
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