Skip to content

Commit

Permalink
fix(utils): format reports with unchanged score
Browse files Browse the repository at this point in the history
  • Loading branch information
hanna-skryl committed Sep 30, 2024
1 parent 5f7b758 commit cddbdd3
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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 |

<details>
<summary><strong>1</strong> audit changed without impacting score</summary>

## 🗃️ 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.

</details>
Original file line number Diff line number Diff line change
@@ -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.

<details>
<summary><strong>1</strong> audit changed without impacting score</summary>

### 🗃️ 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.

</details>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
COMMIT_MOCK,
reportsDiffAddedPluginMock,
reportsDiffAltMock,
reportsDiffChangedMock,
reportsDiffMock,
reportsDiffUnchangedMock,
} from '@code-pushup/test-utils';
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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');
});
});
24 changes: 14 additions & 10 deletions packages/utils/src/lib/reports/generate-md-reports-diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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))),
Expand Down
25 changes: 25 additions & 0 deletions testing/test-utils/src/lib/utils/dynamic-mocks/report-diff.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit cddbdd3

Please sign in to comment.