-
Notifications
You must be signed in to change notification settings - Fork 12
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] Code coverage when merging sharded reports #139
Comments
@edumserrano Yes, it can only merge test reports, but not coverage reports. I don't think we need to transfer the code coverage attachments, because it will generate new code coverage attachments after merged. Long time no see 😊 Currently, MCR has become an independent tool specifically for code coverage, and If we want to continue integrating |
Following the instructions from both Merge Shard Reports and Merge Coverage Reports I've managed to create a single The problem I'm facing now is that the link to the global code coverage options in the merged What I'm doing is running my Playwright tests with two shards:
Then I run the
The link on the On the Note that on the Note
|
It seems a bit complex to merge coverage manually. I will consider whether it can also merge the coverage report when merging the test report. |
I guess it would be nice if merging the test reports would also take care of merging the coverage report. Meanwhile, following the instructions you provided it wasn't hard for me to get something like this: // merge.js
const monocartReporter = require("monocart-reporter");
const coverageReport = require("monocart-coverage-reports");
async function mergeCodeCoverageReportsAsync() {
const inputDir = [
"./shards/1/code-coverage/raw",
"./shards/2/code-coverage/raw",
];
const coverageOptions = {
// this name doesn't seem to have any effect either which makes sense since I'm only merging the coverageOptions variable is only used to merge the code coverage reports, not to "attach" them to the monocart test report.
name: "Merged Coverage Report",
inputDir,
outputDir: "./shards/merged/code-coverage",
sourceFilter: (sourcePath) => {
return (
sourcePath.startsWith("projects/playground/src") ||
sourcePath.startsWith("projects/ngx-module-federation-tools/")
);
},
entryFilter: (entry) => {
return !entry.url.includes("fonts.googleapis.com");
},
reports: [
[
"v8",
{
outputFile: "v8/index.html",
inline: true,
metrics: ["lines"],
},
],
[
"console-summary",
{
metrics: ["lines"],
},
],
],
};
await new coverageReport.CoverageReport(coverageOptions).generate();
}
async function mergeTestReportsAsync() {
const reportDataList = [
"shards/1/monocart-report.json",
"shards/2/monocart-report.json",
"shards/3/monocart-report.json",
"shards/4/monocart-report.json",
];
await monocartReporter.merge(reportDataList, {
name: "My Merged Report",
outputFile: "shards/merged/monocart-report.html",
// the below has no effect
// coverage: {
// name: "new name",
// reportPath: "./shards/merged/code-coverage/v8/index.html",
// }
});
}
async function main() {
await mergeCodeCoverageReportsAsync();
await mergeTestReportsAsync();
};
main(); And when executing with
The directory where the merged reports are outputted looks like this:
With this I'm almost there, there are two things that are missing:
All this to say:
|
Thanks, I have figured out how to merge coverage reports, and also copy attachments to the merged directory when merging test reports. WIP. |
Please try monocart-reporter@2.7.0 Note: The coverage reports will be merged automatically if we specify the // global coverage options
coverage: {
reports: [
// for merging coverage reports
'raw'
]
} |
Testing results from monocart-reporter@2.7.0Perhaps I'm doing something wrong but I got two problems:
How I executed the testI run 4 test executions (4 shards) and then manually copied the output from monocart-reporter into
Then I ran import { MonocartReporterOptions, merge } from "monocart-reporter";
async function mergeTestReportsAsync(): Promise<void> {
const reportDataList: unknown[] = [
"shards/1/monocart-report.json",
"shards/2/monocart-report.json",
"shards/3/monocart-report.json",
"shards/4/monocart-report.json",
];
const options: MonocartReporterOptions = {
name: "My Merged Report",
outputFile: "shards/merged/monocart-report.html",
};
await merge(reportDataList, options);
}
async function main(): Promise<void> {
await mergeTestReportsAsync();
}
main(); This resulted in a
The merged code coverage is incorrect
@cenfun let me know if you need more information. |
coverage options aren't respected during merge - intended?In addition to the feedback above the For instance, after I run the sharded tests, following the same scenario as described in my previous comment, if I run import {
MonocartReporterOptions,
ReportDescription,
merge,
} from "monocart-reporter";
async function mergeTestReportsAsync(): Promise<void> {
const codeCoverageReports: ReportDescription[] = [
[
"v8",
{
outputFile: "v8/index.html",
inline: true,
metrics: ["lines"],
},
],
[
"console-summary",
{
metrics: ["lines"],
},
],
[
"cobertura",
{
file: "cobertura/code-coverage.cobertura.xml",
},
],
[
"lcovonly",
{
file: "lcov/code-coverage.lcov.info",
},
],
];
const reportDataList: unknown[] = [
"shards/1/monocart-report.json",
"shards/2/monocart-report.json",
"shards/3/monocart-report.json",
"shards/4/monocart-report.json",
];
const options: MonocartReporterOptions = {
name: "My Merged Report",
outputFile: "shards/merged/monocart-report.html",
coverage: {
name: "new name",
reportPath: "./shards/merged/code-coverage/v8/index.html",
reports: codeCoverageReports,
}
};
await merge(reportDataList, options);
}
async function main(): Promise<void> {
await mergeTestReportsAsync();
}
main(); I would expect to get different types of code coverage, one for V8, one for console summary, one for cobertura and one for lcovonly. However, I only get a V8 report. The Would this be something that could be supported? If it helps, the scenario for this would be running the Playwright tests in sharded mode in CI, then generating a merged report where:
Another problem with coverage options not being respectedIt means I can't define the monocart-reporter coverage report options on the if (isRunningInShardedMode) {
_codeCoverageReports = [
[
"raw", // used for for merging coverage reports from multiple shards into a single coverage report.
{
outputDir: "raw",
},
],
[
"console-summary",
{
metrics: ["lines"],
},
],
];
} else {
_codeCoverageReports = [
[
"v8",
{
outputFile: v8RelativeFilePath,
inline: true,
metrics: ["lines"],
},
],
[
"console-summary",
{
metrics: ["lines"],
},
],
[
"cobertura",
{
file: "cobertura/code-coverage.cobertura.xml",
},
],
[
"lcovonly",
{
file: "lcov/code-coverage.lcov.info",
},
],
];
} The above sets the monocart-reporter coverage options to only be If I try the above, then when I do the merge I do NOT get any code coverage. This is perhaps because you only generate v8 html code coverage if the I think this should not be the case. After running with the |
SuggestionIt seems that some of these problems come from how you are deciding to merge monocart reports and its code coverage. If we take a look at the merge-cli from Playwright what they suggest is:
If we draw a parallel for the monocart-reporter:
I think a lot of the issues I reported on the previous comments would be solved if the This said, it might be really hard to do this so let me know your thoughts... |
I found that the output directory of raw report is
coverage: {
// I didn't see all the coverage options in your above codes, perhaps you have set `outputDir` like this
// outputDir: "./code-coverage"
reports: [
// We can temporarily use 'console-details' or 'v8' to verify or check if the coverage is corrected, but it doesn't make sense for merging.
//'console-details',
//'v8',
// use for merging and do not set the custom `outputDir` for `raw` too
'raw'
]
},
In fact, the I know the blob reporter. When Playwright did not yet support the blob reporter, Monocart already had the |
Please try monocart-reporter@2.7.1 |
Change the directory from code-coverage to just coverageAs per:
I tried changing the coverage directory to be This is just to keep you informed, to let you know that it didn't work but it doesn't matter much because the behavior is different with version 2.7.1 Testing results from monocart-reporter@2.7.1Note Apologies if I didn't express myself correctly in the previous posts. I didn't mean to say that you should do things like the blob reporter and the merge-cli from Playwright. I was merely trying to use that as an example to point out that when trying to do a merge with monocart-reporter, the merge didn't seem to respect the configuration provided to it (like the fact that it wouldn't obey the code coverage options). Version 2.7.1 changes this though, the code coverage options are now respected and things like the scenario from Another problem with coverage options not being respected are now working as expected. Version 2.7.1 has improved on all of the issues I reported here 🎉. I believe I found a small bug but I'll open a separate issue for it as to not side track this one. Thank you for the quick resolution @cenfun 🥇 |
I've used the documentation about Merge Shard Reports to successfully run my playwright tests in a sharded mode and then merge the
monocart-reporter
reports.The problem I have though is that I'm using the Code Coverage Report feature and each shard contains a
v8
code coverage report file. These files aren't merged using the technique described in the Merge Shard Reports section and though in this section you mention that:That doesn't solve the issue of merging the code coverage reports right? If I manually transfer the code coverage attachments to the expected directory I will have the problem that the different shards have multiple code coverage files with the same directory structure. I would have to overwrite files ending up with the code coverage from only one of the shard runs right?
Any thoughts on this? Am I missing something or this isn't supported yet?
The text was updated successfully, but these errors were encountered: