diff --git a/build-tools/packages/build-cli/src/codeCoverage/compareCodeCoverage.ts b/build-tools/packages/build-cli/src/codeCoverage/compareCodeCoverage.ts index 05d68b8e541d..89113bdd382f 100644 --- a/build-tools/packages/build-cli/src/codeCoverage/compareCodeCoverage.ts +++ b/build-tools/packages/build-cli/src/codeCoverage/compareCodeCoverage.ts @@ -34,7 +34,8 @@ const codeCoverageComparisonIgnoreList: string[] = [ ]; /** - * Type for the code coverage report generated by comparing the baseline and pr code coverage + * Type for the code coverage report generated by comparing the baseline and pr code coverage. We are noting both line and branch coverage + * here but as part of the code coverage comparison check, we are only using branch coverage. */ export interface CodeCoverageComparison { /** @@ -159,8 +160,7 @@ export function getPackagesWithCodeCoverageChanges( // Find existing packages that have reported a change in coverage for the current PR const existingPackagesWithCoverageChange = codeCoverageComparisonData.filter( - (codeCoverageReport) => - codeCoverageReport.branchCoverageDiff !== 0 || codeCoverageReport.lineCoverageDiff !== 0, + (codeCoverageReport) => codeCoverageReport.branchCoverageDiff !== 0, ); logger?.verbose( `Found ${existingPackagesWithCoverageChange.length} packages with code coverage changes`, @@ -184,8 +184,7 @@ export function isCodeCoverageCriteriaPassed( const { codeCoverageComparisonForNewPackages, codeCoverageComparisonForExistingPackages } = codeCoverageChangeForPackages; const packagesWithNotableRegressions = codeCoverageComparisonForExistingPackages.filter( - (codeCoverageReport: CodeCoverageComparison) => - codeCoverageReport.branchCoverageDiff < -1 || codeCoverageReport.lineCoverageDiff < -1, + (codeCoverageReport: CodeCoverageComparison) => codeCoverageReport.branchCoverageDiff < -1, ); logger?.verbose( @@ -194,8 +193,7 @@ export function isCodeCoverageCriteriaPassed( // Code coverage for the newly added package should be less than 50% to fail. const newPackagesWithNotableRegressions = codeCoverageComparisonForNewPackages.filter( - (codeCoverageReport) => - codeCoverageReport.branchCoverageInPr < 50 || codeCoverageReport.lineCoverageInPr < 50, + (codeCoverageReport) => codeCoverageReport.branchCoverageInPr < 50, ); logger?.verbose( diff --git a/build-tools/packages/build-cli/src/codeCoverage/getCommentForCodeCoverage.ts b/build-tools/packages/build-cli/src/codeCoverage/getCommentForCodeCoverage.ts index 8ba80fb57b6f..cb03f7eac83c 100644 --- a/build-tools/packages/build-cli/src/codeCoverage/getCommentForCodeCoverage.ts +++ b/build-tools/packages/build-cli/src/codeCoverage/getCommentForCodeCoverage.ts @@ -73,10 +73,8 @@ const getCodeCoverageSummary = ( const summary = codeCoverageComparisonReport .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), + // Sort the diff summary of packages based on the total coverage diff(branch coverage) + report1.branchCoverageDiff - report2.branchCoverageDiff, ) .map((coverageReport) => getCodeCoverageSummaryForPackages(coverageReport)) .reduce((prev, current) => prev + current); @@ -87,9 +85,9 @@ const getCodeCoverageSummary = ( const getCodeCoverageSummaryForPackages = (coverageReport: CodeCoverageComparison): string => { const metrics = codeCoverageDetailsHeader + getMetricRows(coverageReport); - return `
${getGlyphForHtml(coverageReport.branchCoverageDiff + coverageReport.lineCoverageDiff)} ${ + return `
${getGlyphForHtml(coverageReport.branchCoverageDiff)} ${ coverageReport.packagePath - }:
Line Coverage Change: ${formatDiff(coverageReport.lineCoverageDiff)}    Branch Coverage Change: ${formatDiff( + }:

 Branch Coverage Change: ${formatDiff( coverageReport.branchCoverageDiff, )}
${metrics}
`; }; @@ -114,23 +112,14 @@ const formatDiff = (coverageDiff: number): string => { }; const getMetricRows = (codeCoverageComparisonReport: CodeCoverageComparison): string => { - const glyphForLineCoverage = getGlyphForHtml(codeCoverageComparisonReport.lineCoverageDiff); const glyphForBranchCoverage = getGlyphForHtml( codeCoverageComparisonReport.branchCoverageDiff, ); - return ( - ` + return ` Branch Coverage ${codeCoverageComparisonReport.branchCoverageInBaseline.toFixed(2)}% ${codeCoverageComparisonReport.branchCoverageInPr.toFixed(2)}% ${glyphForBranchCoverage} ${formatDiff(codeCoverageComparisonReport.branchCoverageDiff)} - ` + - ` - Line Coverage - ${codeCoverageComparisonReport.lineCoverageInBaseline.toFixed(2)}% - ${codeCoverageComparisonReport.lineCoverageInPr.toFixed(2)}% - ${glyphForLineCoverage} ${formatDiff(codeCoverageComparisonReport.lineCoverageDiff)} - ` - ); + `; }; diff --git a/build-tools/packages/build-cli/src/commands/report/codeCoverage.ts b/build-tools/packages/build-cli/src/commands/report/codeCoverage.ts index 4722853c8ac6..5d744234716e 100644 --- a/build-tools/packages/build-cli/src/commands/report/codeCoverage.ts +++ b/build-tools/packages/build-cli/src/commands/report/codeCoverage.ts @@ -194,7 +194,7 @@ export default class ReportCodeCoverageCommand extends BaseCommand< const summaryFooterOnFailure = "### What to do if the code coverage check fails:\n" + - "- Ideally, add more tests to increase the code coverage for the package(s) whose code-coverage regressed.\n" + + "- Ideally, add more tests to increase the code coverage for the package(s) whose code-coverage regressed. Currently, we are only checking branch coverage for the code coverage check.\n" + "- If a regression is causing the build to fail and is due to removal of tests, removal of code with lots of tests or any other valid reason, there is a checkbox further up in this comment that determines if the code coverage check should fail the build or not. You can check the box and trigger the build again. The test coverage analysis will still be done, but it will not fail the build if a regression is detected.\n" + "- Unchecking the checkbox and triggering another build should go back to failing the build if a test-coverage regression is detected.\n\n" + "- You can check which lines are covered or not covered by your tests with these steps:\n" +