From 7a7263c69ea2c2ba4f8ecfd473cdcda31d8e7a96 Mon Sep 17 00:00:00 2001 From: Jatin Garg <48029724+jatgarg@users.noreply.github.com> Date: Tue, 8 Oct 2024 15:34:24 -0700 Subject: [PATCH] Modify comment syntax for code coverage (#22752) ## Description Modify comment for code coverage. Add the line coverage summary to the summary. Co-authored-by: Jatin Garg --- .../codeCoverage/getCommentForCodeCoverage.ts | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/build-tools/packages/build-cli/src/codeCoverage/getCommentForCodeCoverage.ts b/build-tools/packages/build-cli/src/codeCoverage/getCommentForCodeCoverage.ts index 9fc922909cba..3c7a5ae7bce9 100644 --- a/build-tools/packages/build-cli/src/codeCoverage/getCommentForCodeCoverage.ts +++ b/build-tools/packages/build-cli/src/codeCoverage/getCommentForCodeCoverage.ts @@ -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); @@ -81,21 +87,23 @@ const getCodeCoverageSummary = ( const getCodeCoverageSummaryForPackages = (coverageReport: CodeCoverageComparison): string => { const metrics = codeCoverageDetailsHeader + getMetricRows(coverageReport); - return `
${getColorGlyph(coverageReport.branchCoverageDiff)} ${ + return `
${getColorGlyph(coverageReport.branchCoverageDiff + coverageReport.lineCoverageDiff)} ${ coverageReport.packagePath - }: ${formatDiff(coverageReport.branchCoverageDiff)}${metrics}
`; + }:

Line Coverage Change: ${formatDiff(coverageReport.lineCoverageDiff)} Branch Coverage Change: ${formatDiff( + coverageReport.branchCoverageDiff, + )}
${metrics}
`; }; -const getColorGlyph = (codeCoverageBranchDiff: number): string => { - if (codeCoverageBranchDiff === 0) { - return ''; +const getColorGlyph = (codeCoverageDiff: number): string => { + if (codeCoverageDiff === 0) { + return "■"; } - if (codeCoverageBranchDiff > 0) { - return ''; + if (codeCoverageDiff > 0) { + return "⯅"; } - return ''; + return "⯅⯅"; }; const formatDiff = (coverageDiff: number): string => { @@ -114,14 +122,14 @@ const getMetricRows = (codeCoverageComparisonReport: CodeCoverageComparison): st return ( ` Branch Coverage - ${formatDiff(codeCoverageComparisonReport.branchCoverageInBaseline)} - ${formatDiff(codeCoverageComparisonReport.branchCoverageInPr)} + ${codeCoverageComparisonReport.branchCoverageInBaseline.toFixed(2)}% + ${codeCoverageComparisonReport.branchCoverageInPr.toFixed(2)}% ${glyphForBranchCoverage} ${formatDiff(codeCoverageComparisonReport.branchCoverageDiff)} ` + ` Line Coverage - ${formatDiff(codeCoverageComparisonReport.lineCoverageInBaseline)} - ${formatDiff(codeCoverageComparisonReport.lineCoverageInPr)} + ${codeCoverageComparisonReport.lineCoverageInBaseline.toFixed(2)}% + ${codeCoverageComparisonReport.lineCoverageInPr.toFixed(2)}% ${glyphForLineCoverage} ${formatDiff(codeCoverageComparisonReport.lineCoverageDiff)} ` );