From cddbdd35d9ea0ca3cb6b36cf5baac3bfaa0df8ea Mon Sep 17 00:00:00 2001 From: hanna-skryl Date: Thu, 26 Sep 2024 17:12:13 -0400 Subject: [PATCH] fix(utils): format reports with unchanged score --- .../__snapshots__/report-diff-changed.md | 28 +++++++++++++++++++ .../report-diff-monorepo-changed.md | 26 +++++++++++++++++ ...nerate-md-reports-diff.integration.test.ts | 15 ++++++++++ .../lib/reports/generate-md-reports-diff.ts | 24 +++++++++------- .../utils/dynamic-mocks/report-diff.mock.ts | 25 +++++++++++++++++ 5 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 packages/utils/src/lib/reports/__snapshots__/report-diff-changed.md create mode 100644 packages/utils/src/lib/reports/__snapshots__/report-diff-monorepo-changed.md diff --git a/packages/utils/src/lib/reports/__snapshots__/report-diff-changed.md b/packages/utils/src/lib/reports/__snapshots__/report-diff-changed.md new file mode 100644 index 000000000..b35bf461d --- /dev/null +++ b/packages/utils/src/lib/reports/__snapshots__/report-diff-changed.md @@ -0,0 +1,28 @@ +# Code PushUp + +๐Ÿคจ Code PushUp report has both **improvements and regressions** โ€“ compared target commit 0123456789abcdef0123456789abcdef01234567 with source commit abcdef0123456789abcdef0123456789abcdef01. + +## ๐Ÿท๏ธ Categories + +| ๐Ÿท๏ธ Category | โญ Score | +| :------------- | :-----: | +| Performance | ๐ŸŸข 92 | +| Bug prevention | ๐ŸŸก 68 | +| Code style | ๐ŸŸก 54 | + +
+1 audit changed without impacting score + +## ๐Ÿ—ƒ๏ธ Groups + +All of 2 groups are unchanged. + +## ๐Ÿ›ก๏ธ Audits + +| ๐Ÿ”Œ Plugin | ๐Ÿ›ก๏ธ Audit | ๐Ÿ“ Previous value | ๐Ÿ“ Current value | ๐Ÿ”„ Value change | +| :----------------------------------------------------------------- | :------------------------------------------------------------------------------- | :---------------: | :----------------: | :-----------------------------------------------------------------------------------: | +| [ESLint](https://www.npmjs.com/package/@code-pushup/eslint-plugin) | [Disallow unused variables](https://eslint.org/docs/latest/rules/no-unused-vars) | ๐ŸŸฅ 12 warnings | ๐ŸŸฅ **10 warnings** | ![โ†“ โˆ’16.7โ€‰%](https://img.shields.io/badge/%E2%86%93%20%E2%88%9216.7%E2%80%89%25-gray) | + +53 other audits are unchanged. + +
diff --git a/packages/utils/src/lib/reports/__snapshots__/report-diff-monorepo-changed.md b/packages/utils/src/lib/reports/__snapshots__/report-diff-monorepo-changed.md new file mode 100644 index 000000000..8a7733e30 --- /dev/null +++ b/packages/utils/src/lib/reports/__snapshots__/report-diff-monorepo-changed.md @@ -0,0 +1,26 @@ +# Code PushUp + +๐Ÿคจ Code PushUp report has both **improvements and regressions** โ€“ compared target commit 0123456789abcdef0123456789abcdef01234567 with source commit abcdef0123456789abcdef0123456789abcdef01. + +## ๐Ÿ’ผ Project `web` + +๐Ÿคจ Code PushUp report has both **improvements and regressions**. + +All of 3 categories are unchanged. + +
+1 audit changed without impacting score + +### ๐Ÿ—ƒ๏ธ Groups + +All of 2 groups are unchanged. + +### ๐Ÿ›ก๏ธ Audits + +| ๐Ÿ”Œ Plugin | ๐Ÿ›ก๏ธ Audit | ๐Ÿ“ Previous value | ๐Ÿ“ Current value | ๐Ÿ”„ Value change | +| :----------------------------------------------------------------- | :------------------------------------------------------------------------------- | :---------------: | :----------------: | :-----------------------------------------------------------------------------------: | +| [ESLint](https://www.npmjs.com/package/@code-pushup/eslint-plugin) | [Disallow unused variables](https://eslint.org/docs/latest/rules/no-unused-vars) | ๐ŸŸฅ 12 warnings | ๐ŸŸฅ **10 warnings** | ![โ†“ โˆ’16.7โ€‰%](https://img.shields.io/badge/%E2%86%93%20%E2%88%9216.7%E2%80%89%25-gray) | + +53 other audits are unchanged. + +
diff --git a/packages/utils/src/lib/reports/generate-md-reports-diff.integration.test.ts b/packages/utils/src/lib/reports/generate-md-reports-diff.integration.test.ts index f1a55a2d8..3cbd48c10 100644 --- a/packages/utils/src/lib/reports/generate-md-reports-diff.integration.test.ts +++ b/packages/utils/src/lib/reports/generate-md-reports-diff.integration.test.ts @@ -3,6 +3,7 @@ import { COMMIT_MOCK, reportsDiffAddedPluginMock, reportsDiffAltMock, + reportsDiffChangedMock, reportsDiffMock, reportsDiffUnchangedMock, } from '@code-pushup/test-utils'; @@ -58,6 +59,12 @@ describe('generateMdReportsDiff', () => { ).toMatchFileSnapshot('__snapshots__/report-diff-unchanged.md'); }); + it('should format Markdown comment for reports diff with changes that do not impact score', async () => { + await expect( + generateMdReportsDiff(reportsDiffChangedMock()), + ).toMatchFileSnapshot('__snapshots__/report-diff-changed.md'); + }); + it('should format Markdown comment for reports diff with added plugin', async () => { await expect( generateMdReportsDiff(reportsDiffAddedPluginMock()), @@ -138,4 +145,12 @@ describe('generateMdReportsDiffForMonorepo', () => { ]), ).toMatchFileSnapshot('__snapshots__/report-diff-monorepo-unchanged.md'); }); + + it('should format Markdown comment with changes that do not impact score', async () => { + await expect( + generateMdReportsDiffForMonorepo([ + { ...reportsDiffChangedMock(), label: 'web' }, + ]), + ).toMatchFileSnapshot('__snapshots__/report-diff-monorepo-changed.md'); + }); }); diff --git a/packages/utils/src/lib/reports/generate-md-reports-diff.ts b/packages/utils/src/lib/reports/generate-md-reports-diff.ts index 673e4dbb3..7e40218d8 100644 --- a/packages/utils/src/lib/reports/generate-md-reports-diff.ts +++ b/packages/utils/src/lib/reports/generate-md-reports-diff.ts @@ -142,16 +142,6 @@ function createCategoriesTable( const { changed, unchanged, added } = diff.categories; const { hasChanges, skipUnchanged } = options; - const columns: TableColumnObject[] = [ - { heading: '๐Ÿท๏ธ Category', alignment: 'left' }, - { - heading: hasChanges ? 'โญ Previous score' : 'โญ Score', - alignment: 'center', - }, - { heading: 'โญ Current score', alignment: 'center' }, - { heading: '๐Ÿ”„ Score change', alignment: 'center' }, - ]; - const rows: TableRow[] = [ ...sortChanges(changed).map(category => [ formatTitle(category), @@ -177,6 +167,20 @@ function createCategoriesTable( ])), ]; + if (rows.length === 0) { + return [[], []]; + } + + const columns: TableColumnObject[] = [ + { heading: '๐Ÿท๏ธ Category', alignment: 'left' }, + { + heading: hasChanges ? 'โญ Previous score' : 'โญ Score', + alignment: 'center', + }, + { heading: 'โญ Current score', alignment: 'center' }, + { heading: '๐Ÿ”„ Score change', alignment: 'center' }, + ]; + return [ hasChanges ? columns : columns.slice(0, 2), rows.map(row => (hasChanges ? row : row.slice(0, 2))), diff --git a/testing/test-utils/src/lib/utils/dynamic-mocks/report-diff.mock.ts b/testing/test-utils/src/lib/utils/dynamic-mocks/report-diff.mock.ts index 37b1ecbb1..c043756b9 100644 --- a/testing/test-utils/src/lib/utils/dynamic-mocks/report-diff.mock.ts +++ b/testing/test-utils/src/lib/utils/dynamic-mocks/report-diff.mock.ts @@ -336,6 +336,31 @@ export function reportsDiffUnchangedMock(): ReportsDiff { }; } +export function reportsDiffChangedMock(): ReportsDiff { + const originalDiff = reportsDiffUnchangedMock(); + return { + ...originalDiff, + audits: { + ...originalDiff.audits, + changed: [ + { + slug: 'no-unused-vars' satisfies ESLintAuditSlug, + title: ESLINT_AUDITS_MAP['no-unused-vars'].title, + docsUrl: ESLINT_AUDITS_MAP['no-unused-vars'].docsUrl, + plugin: { + slug: ESLINT_PLUGIN_META.slug, + title: ESLINT_PLUGIN_META.title, + docsUrl: ESLINT_PLUGIN_META.docsUrl, + }, + scores: { before: 0, after: 0, diff: 0 }, + values: { before: 12, after: 10, diff: -2 }, + displayValues: { before: '12 warnings', after: '10 warnings' }, + }, + ], + }, + }; +} + export function reportsDiffAddedPluginMock(): ReportsDiff { const originalDiff = reportsDiffAltMock(); return {