-
-
Notifications
You must be signed in to change notification settings - Fork 359
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
Merging coverage files doesn't produce accurate cumulative result #1302
Comments
This is difficult for us to support as you are not using nyc to generate any coverage. From the limited information you shared I see some version conflicts:
As for your command, Further you have not linked a repository as required so we do not know how you are even running the tests, what kind of configurations you are using, etc. |
Thanks for your response. Yes, Jest has the istanbul instrumenter built in, so I tried to align other dependencies to that, because before the downgrade I got this error: You're right the command I posted is wrong, but I used the correct one, so it's a typo. Yes, sorry for that, I was hoping the information I supplies would be enough, because my production setup if fairly complex with a mix of nx with angular, cypress, jest and nyc. It would take some time to duplicate that setup. I've tried to bump jest to the latest version (25.3.0) but wasn't able to merge. I'll try to make it work with [email protected], if the problems persists I'll make a demo project or else I'll close the issue. EDIT
And [email protected]. This resulted in I've replaced istanbul-instrumenter-loader with babel-plugin-istanbul, so the outdated istanbul-lib-instrument is gone. The coverage files still cannot be merged with the one Jest produces. |
@D0rmouse the reason you're still getting this error Make sure these happen:
"coverageReporters": [
"lcov",
"text",
"json"
] The important part being that there's a
Hope it helps 🤞 |
@lirantal I do have a json entry in my coverageReporters array. I got json from the start it's just not merging correctly because the formats don't match. |
@D0rmouse can you confirm that you have that file called |
@lirantal Yes I can, the output of the Jest test is simply different than my Cypress coverage output. |
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
I am facing the same issue as the above user @CharlesStover |
My issue ended up simply being that the version of Jest needed to be downgraded to 26. No idea why 27 is broken. The instrumentation of Jest 27 is simply off and doesn't match the one generated by |
I am trying to integrate this to existing application which is using Jest 27.0.6 and can't downgrade to lower version. |
I spent a long time trying to fix it, and was not able to solve it with Jest 27. A downgrade to 26 resolved it like magic. This may need to be a bug report for the Jest team, as it appears 27 is not instrumenting coverage correctly, producing incorrect results for TypeScript files (this occurs with either If you want to open a ticket with the Jest team, I think that's the right solution, and you could link to my screenshots and data in this issue as a reference for them. |
I have the same issue just by merging multiple reports from various cypress runs in parallel. The merge is just taking the last report base on the order:
{
"global.component.ts": {
// ...same value in both files
"s": {
"0": 0,
"1": 0,
"2": 0,
"3": 0,
"4": 0,
"5": 0,
"6": 0,
"7": 0,
"8": 0,
"9": 0,
"10": 0,
"11": 0,
"12": 0,
"13": 0,
"14": 0,
"15": 0,
"16": 0,
"17": 0,
"18": 0,
"19": 0,
"20": 64,
"21": 0
},
"f": { "0": 0 },
"b": { "0": [0, 0] }
}
}
{
"global.component.ts": {
// ...same value in both files
"s": {
"0": 77,
"1": 77,
"2": 5151,
"3": 77,
"4": 77,
"5": 5151,
"6": 77,
"7": 77,
"8": 5151,
"9": 77,
"10": 77,
"11": 5151,
"12": 77,
"13": 77,
"14": 5151,
"15": 77,
"16": 77,
"17": 77,
"18": 77,
"19": 77,
"20": 154,
"21": 77
},
"f": { "0": 77 },
"b": { "0": [77, 77] }
} In this case, only the result of Any ideas? Should rewrite a merge myself? |
Use storybook test-runner and `@storybook/addon-coverage` to get visual coverage report. The setup requires spinning up storybook before generating the coverage numbers. Now, we have three test scripts: - test => combined test coverage - test:unit => jest test coverage only - test:visual => story book coverage only (note: this only collect coverage on src/components) Updated coverage github action to also create/update comment which display code coverage percentage for unit, visual, and combined tests the test-runner only works with jest v27 right now. As nidhi noted in her [pr](#274), storybook will be adding support for v28 shortly (storybookjs/test-runner#154). [playwright](https://www.npmjs.com/package/playwright) library is needed in the github action for test-storybook. <img width="600" alt="Screen Shot 2022-08-03 at 4 51 03 PM" src="https://user-images.githubusercontent.com/36055303/182709211-0189bad6-e978-4f82-9ee4-ba62be350283.png"> NOTE: The report generated from `nyc` merge command may not be super accurate after some comparison between to the unit vs visual vs merge report (ex: [github issue](istanbuljs/nyc#1302)). J=SLAP-2269 & SLAP-2270 TEST=manual&auto - See that running `npm run test:visual` generates lcov report in coverage/visual folder. And the report is printed out in terminal. - See that a comment is made to the PR about the three coverage percentages. - See that coverall percentage increase without changes to tests (increased due to combined test coverage)
@D0rmouse did you finally find a good configuration to combine multiple coverage reports? I have the same type of stack with Nx + Cypress + Storybook + Jest, generating reports separately works fine but when I want to merge, it is not good. It makes sense because each tool are using different versions for each generation. |
Use storybook test-runner and `@storybook/addon-coverage` to get visual coverage report. The setup requires spinning up storybook before generating the coverage numbers. Now, we have three test scripts: - test => combined test coverage - test:unit => jest test coverage only - test:visual => story book coverage only (note: this only collect coverage on src/components) Updated coverage github action to also create/update comment which display code coverage percentage for unit, visual, and combined tests the test-runner only works with jest v27 right now. As nidhi noted in her [pr](#274), storybook will be adding support for v28 shortly (storybookjs/test-runner#154). [playwright](https://www.npmjs.com/package/playwright) library is needed in the github action for test-storybook. <img width="600" alt="Screen Shot 2022-08-03 at 4 51 03 PM" src="https://user-images.githubusercontent.com/36055303/182709211-0189bad6-e978-4f82-9ee4-ba62be350283.png"> NOTE: The report generated from `nyc` merge command may not be super accurate after some comparison between to the unit vs visual vs merge report (ex: [github issue](istanbuljs/nyc#1302)). J=SLAP-2269 & SLAP-2270 TEST=manual&auto - See that running `npm run test:visual` generates lcov report in coverage/visual folder. And the report is printed out in terminal. - See that a comment is made to the PR about the three coverage percentages. - See that coverall percentage increase without changes to tests (increased due to combined test coverage)
Hi all, |
Same issue. Any updates. Screenshots below: I'm using nyc merge and nyc report just like the original reporter of this issue. The final JSON just doesn't appear correct. @mmisty I tried your suggestion and it didn't work. I end up with this instead: |
@sscaff1, hi Steven Key points as I remember:
JestCypressMerged: |
In my case, I fixed this issue by using the babel coverage provider in my Jest config
To run this in instrument mode, add a script like this to your package.json This finally provides accurate coverage results for me. |
I was facing the same issue as OP mentioned, as well as of other people here in the thread. My issue was a wrong merged report based on:
Snooping around at the code/produced reports, I found that:
So the actual problem was getting one or the other inline with their counterpart. First I tried to force my npm dependencies to all be the same, assuming this was the issue (different versions of istanbul, which I did have installed): Example
But that was a dud, as the problem lied with
That seems to have finally aligned the stars, and there a difference of about 300 lines, which I suspect is some other config I still have to tweak. |
I'm encountering the same problem. When I try to merge two coverage-final.json files, the output is erroneous. |
I am having the same issue. I add both coverage files I generated: This one was generated using vitest coverage-final.json Here are my configs for vitest coverage: {
all: true,
clean: false,
exclude: [
...
],
provider: 'istanbul',
reporter: ['json', 'html']
}
},
// my command
"test:coverage": "vitest --run --coverage", For storybook I used: addons: [
{
name: '@storybook/addon-coverage',
options: {
istanbul: {
exclude: [
....
]
}
}
},
]
"test-storybook:coverage": "test-storybook --coverage --json --coverageDirectory=./coverage", At the end I use
In my merged coverage report I can then see: However, when looking at only the unit test report, I can see that these lines are being hitted. Okay I digged a little bit and it seems that the storybook addon and vitest generate slightly different line and column for the statements. For example in one component vitest said that there is a stmt on line 38 start at col 18 and ends on the same line. "2": {
"start": {
"line": 38,
"column": 18
},
"end": {
"line": 38,
"column": null
}
}, However, storybook coverage report says the statement is on line 38 in column 2: "3": {
"start": {
"line": 38,
"column": 2
},
"end": {
"line": 38,
"column": null
}
}, So now the question becomes how can I make sure that both instrumentalize the code the same way? |
This happens with vitest 1.2.1, cypress 13.2.0, and @cypress/code-coverage 3.12.19 as well |
I am also facing same issue. I am trying to migrate from jest to vitest and some tests are written so bad that I have to keep them in jest for time being but when I try to merge the coverage reports from jest and vitest it just generates wrong combined numbers. |
I can see what nyc version cypress code coverage plugin uses. How can I check what inbuilt nyc version a given jest release uses? UPDATE: after making sure nyc versions (jest, cypress/code-coverage) match, I can confirm this issue is still happening. |
I execute the following nyc commands, after generating individual coverage reports on the same codebase using different test executions run by Jest and Cypress.
nyc merge coverage-jest combined/coverage-jest.json
nyc merge coverage-cypress combined/coverage-cypress.json
nyc report combined --reporter html --reporter text
Expected Behavior
I'd expect this to show a correct cumulative coverage report of .ts and .html files.
Observed Behavior
Cannot read property 'locations' of undefined
TypeError
is shown.Troubleshooting steps
cache: false
in my nyc configEnvironment Information
For Cypress coverage I use above dependencies as well as
@cypress/code-coverage:^3.0.2
.I'm using
jest: 24.1.0
to produce unit test coverage.The text was updated successfully, but these errors were encountered: