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

Modify comment syntax for code coverage #22752

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ const getCodeCoverageSummary = (
codeCoverageComparisonReport: CodeCoverageComparison[],
): string => {
const summary = codeCoverageComparisonReport
.sort((report1, report2) => report1.branchCoverageDiff - report2.branchCoverageDiff)
.sort(
(report1, report2) =>
// Sort the diff summary of packages based on the total coverage diff(line coverage + branch coverage)
report1.branchCoverageDiff +
report1.lineCoverageDiff -
(report2.branchCoverageDiff + report2.lineCoverageDiff),
)
.map((coverageReport) => getCodeCoverageSummaryForPackages(coverageReport))
.reduce((prev, current) => prev + current);

Expand All @@ -81,21 +87,23 @@ const getCodeCoverageSummary = (
const getCodeCoverageSummaryForPackages = (coverageReport: CodeCoverageComparison): string => {
const metrics = codeCoverageDetailsHeader + getMetricRows(coverageReport);

return `<details><summary><b>${getColorGlyph(coverageReport.branchCoverageDiff)} ${
return `<details><summary><b>${getColorGlyph(coverageReport.branchCoverageDiff + coverageReport.lineCoverageDiff)} ${
coverageReport.packagePath
}:</b> ${formatDiff(coverageReport.branchCoverageDiff)}</summary>${metrics}</table></details>`;
}:</b> <br> Line Coverage Change: ${formatDiff(coverageReport.lineCoverageDiff)} Branch Coverage Change: ${formatDiff(
coverageReport.branchCoverageDiff,
)}</summary>${metrics}</table></details>`;
};

const getColorGlyph = (codeCoverageBranchDiff: number): string => {
if (codeCoverageBranchDiff === 0) {
return '<span style="color: green">■</span>';
const getColorGlyph = (codeCoverageDiff: number): string => {
if (codeCoverageDiff === 0) {
return "■";
}

if (codeCoverageBranchDiff > 0) {
return '<span style="color: green">⯅</span>';
if (codeCoverageDiff > 0) {
return "⯅";
}

return '<span style="color: red">⯆</span>';
return "⯅⯅";
};

const formatDiff = (coverageDiff: number): string => {
Expand All @@ -114,14 +122,14 @@ const getMetricRows = (codeCoverageComparisonReport: CodeCoverageComparison): st
return (
`<tr>
<td>Branch Coverage</td>
<td>${formatDiff(codeCoverageComparisonReport.branchCoverageInBaseline)}</td>
<td>${formatDiff(codeCoverageComparisonReport.branchCoverageInPr)}</td>
<td>${codeCoverageComparisonReport.branchCoverageInBaseline.toFixed(2)}%</td>
<td>${codeCoverageComparisonReport.branchCoverageInPr.toFixed(2)}%</td>
<td>${glyphForBranchCoverage} ${formatDiff(codeCoverageComparisonReport.branchCoverageDiff)}</td>
</tr>` +
`<tr>
<td>Line Coverage</td>
<td>${formatDiff(codeCoverageComparisonReport.lineCoverageInBaseline)}</td>
<td>${formatDiff(codeCoverageComparisonReport.lineCoverageInPr)}</td>
<td>${codeCoverageComparisonReport.lineCoverageInBaseline.toFixed(2)}%</td>
<td>${codeCoverageComparisonReport.lineCoverageInPr.toFixed(2)}%</td>
<td>${glyphForLineCoverage} ${formatDiff(codeCoverageComparisonReport.lineCoverageDiff)}</td>
</tr>`
);
Expand Down
Loading