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

[Question] can we use multiple v8-json files to merge coverage? #78

Closed
stevez opened this issue Sep 17, 2024 · 8 comments
Closed

[Question] can we use multiple v8-json files to merge coverage? #78

stevez opened this issue Sep 17, 2024 · 8 comments

Comments

@stevez
Copy link

stevez commented Sep 17, 2024

In order to merge multiple v8 coverage report, does monocart support merging json files instead of raw files like nyc for Istanbul?

@cenfun
Copy link
Owner

cenfun commented Sep 17, 2024

The v8-json you said is generated by NODE_V8_COVERAGE?
If so, we can use option dataDir (not inputDir)

{
  // ...
  dataDir: "./coverage/v8-coverage"
  // ...
}

see example: https://github.com/tstyche/tstyche/blob/main/scripts/report-coverage.js

Also there is API addFromDir

await mcr.addFromDir("./coverage/v8-coverage");
await mcr.generate();

The MCR will automatically merge all the added coverage data when executing generate()

await mcr.addFromDir("./coverage/v8-coverage1");
await mcr.addFromDir("./coverage/v8-coverage2");
await mcr.generate();

@stevez
Copy link
Author

stevez commented Sep 17, 2024

V8-json is one of the format your report provided. What I mean is I found using raw files to merge is a little bit complicated: it still need to scan the source folder, and the config for merging report needs to combine both playwright report config and jest report config. So I am thinking if jest and playwright both generate v8 json files, and both include all files information, it would be great if we can just merge 2 json files

@cenfun
Copy link
Owner

cenfun commented Sep 17, 2024

I see, you are using monocart-reporter + Playwright.
The monocart-reporter is a test report but integrates MCR as coverage report.
When merging the test reports, the coverage reports will be merged automatically if we specify the raw report in coverage options. (since version monocart-reporter v2.7.0)
I don't think there's a better way to do the merging currently.

However, perhaps we could try using independent MCR to collect and generate coverage reports directly (without monocart-reporter).
see example https://github.com/cenfun/playwright-coverage

@cenfun
Copy link
Owner

cenfun commented Sep 17, 2024

BTW, if you are using Github Actions or similar CI/CD workflow/piplines like Jenkins, there should be a way to upload and download the artifacts in a job, we can easily transfer and use these artifacts (zip all json files) to merge reports.

see GithubActions example: https://github.com/cenfun/merge-code-coverage/blob/main/.github/workflows/main.yml

@stevez
Copy link
Author

stevez commented Sep 17, 2024

Could you explain details how your example can help?

My use case is exactly same as this: https://github.com/cenfun/merge-code-coverage

I wonder if we can simply merge the generated coverage-report.json files

@cenfun
Copy link
Owner

cenfun commented Sep 17, 2024

No, We can not merge with the generated coverage-report.json files
The coverage-report.json is the data file generated for HTML report (V8 only), It does not include the original coverage range data which is used for the merging algorithm.
We can only merge with the raw data (raw report data or raw V8 coverage data), it includes all the coverage info we need.

@cenfun
Copy link
Owner

cenfun commented Sep 17, 2024

In fact, merging coverage data is very complex. Even for Istanbul nyc, there are still some issues with merging

The possible reason is that different versions of istanbul-lib-instrument or related compiler lead to variations in the coverage data. At this point, it should be an advantage for the V8 format.

@stevez
Copy link
Author

stevez commented Sep 17, 2024

Got it, thank you

@cenfun cenfun closed this as completed Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants