From d8a7eb25f602847ada6cbcd5c5f960a601bfff3a Mon Sep 17 00:00:00 2001 From: hanna-skryl Date: Tue, 22 Oct 2024 19:49:54 -0400 Subject: [PATCH] fix(utils): always log single perfect audit --- .../utils/src/lib/reports/log-stdout-summary.ts | 7 ++++--- .../lib/reports/log-stdout-summary.unit.test.ts | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/utils/src/lib/reports/log-stdout-summary.ts b/packages/utils/src/lib/reports/log-stdout-summary.ts index d4918adde..e6a397f2c 100644 --- a/packages/utils/src/lib/reports/log-stdout-summary.ts +++ b/packages/utils/src/lib/reports/log-stdout-summary.ts @@ -39,9 +39,10 @@ export function logPlugins( ): void { plugins.forEach(plugin => { const { title, audits } = plugin; - const filteredAudits = verbose - ? audits - : audits.filter(({ score }) => score !== 1); + const filteredAudits = + verbose || audits.length === 1 + ? audits + : audits.filter(({ score }) => score !== 1); const diff = audits.length - filteredAudits.length; logAudits(title, filteredAudits); diff --git a/packages/utils/src/lib/reports/log-stdout-summary.unit.test.ts b/packages/utils/src/lib/reports/log-stdout-summary.unit.test.ts index 0dd80be0c..fbcc85879 100644 --- a/packages/utils/src/lib/reports/log-stdout-summary.unit.test.ts +++ b/packages/utils/src/lib/reports/log-stdout-summary.unit.test.ts @@ -255,6 +255,21 @@ describe('logPlugins', () => { expect(output).toContain('Audit 1'); expect(output).toContain('Audit 2'); }); + + it('should not truncate a perfect audit in non-verbose mode when it is the only audit available', () => { + logPlugins( + [ + { + title: 'Best Practices', + slug: 'best-practices', + audits: [{ title: 'Audit 1', score: 1, value: 100 }], + }, + ] as ScoredReport['plugins'], + false, + ); + const output = logs.join('\n'); + expect(output).toContain('Audit 1'); + }); }); describe('binaryIconPrefix', () => {