From 06eeaf22120788fa50fdbda856628c538bdeee04 Mon Sep 17 00:00:00 2001 From: jdalton Date: Wed, 11 Nov 2026 12:23:53 -0500 Subject: [PATCH] test(report): keep output formats aligned across folds --- .../scan/output-scan-report-text.test.mts | 68 ++++++++++++++++--- 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/src/commands/scan/output-scan-report-text.test.mts b/src/commands/scan/output-scan-report-text.test.mts index 082b68fad7..5da02fe0dc 100644 --- a/src/commands/scan/output-scan-report-text.test.mts +++ b/src/commands/scan/output-scan-report-text.test.mts @@ -209,8 +209,13 @@ describe('toPlainTextReport', () => { expect(text).toContain('package-199999') }) - it('keeps package versions accurate across fold modes', () => { - const leaf = alert('error', 'envVars', 'package.json', '') + it('keeps report fields aligned across formats and fold modes', () => { + const leaf = alert( + 'error', + 'envVars', + 'package.json', + 'https://socket.dev/npm/package/demo-transitive', + ) const versionFoldAlerts: ScanReport['alerts'] = new Map([ ['npm', new Map([['demo-transitive', new Map([['2.3.4', leaf]])]])], ]) @@ -227,7 +232,12 @@ describe('toPlainTextReport', () => { ['package.json', leaf], [ 'src/index.js', - alert('warn', 'telemetry', 'package-lock.json', ''), + alert( + 'warn', + 'telemetry', + 'package-lock.json', + 'https://socket.dev/npm/package/demo-transitive', + ), ], ]), ], @@ -247,7 +257,15 @@ describe('toPlainTextReport', () => { 'demo-transitive', new Map([ ['2.3.4', leaf], - ['2.3.5', alert('warn', 'telemetry', 'package.json', '')], + [ + '2.3.5', + alert( + 'warn', + 'telemetry', + 'package.json', + 'https://socket.dev/npm/package/demo-transitive', + ), + ], ]), ], ]), @@ -268,6 +286,11 @@ describe('toPlainTextReport', () => { fold: FOLD_SETTING_PKG, healthy: false, }) + const defaultFoldReport = buildReport({ alerts: buildAlerts() }) + const twoVersionReport = buildReport({ + alerts: twoVersionAlerts, + fold: 'version', + }) expect(flattenReportAlerts(versionFoldReport)[0]?.packageVersion).toBe( '2.3.4', @@ -291,11 +314,38 @@ describe('toPlainTextReport', () => { '', ) expect(toPlainTextReport(packageFoldReport)).toContain('') - expect( - flattenReportAlerts( - buildReport({ alerts: twoVersionAlerts, fold: 'version' }), - ).map(row => row.packageVersion), - ).toEqual(['2.3.4', '2.3.5']) + expect(flattenReportAlerts(twoVersionReport).map(row => row.packageVersion)) + .toEqual(['2.3.4', '2.3.5']) + const reports = [ + defaultFoldReport, + versionFoldReport, + fileFoldReport, + packageFoldReport, + twoVersionReport, + ] + + for (const report of reports) { + const rows = flattenReportAlerts(report) + const text = toPlainTextReport(report) + const markdown = toMarkdownReport(report) + const markdownHeader = markdown + .split('\n') + .find(line => line.includes('| Policy |')) + + expect(text).toContain('VERSION') + expect(markdownHeader).toContain('Version') + expect(markdownHeader).toContain('URL') + for (const row of rows) { + expect(text).toContain(row.packageVersion) + expect(markdown).toContain(row.packageVersion) + expect(text).toContain(row.manifest) + expect(markdown).toContain(row.manifest) + if (row.url) { + expect(text).toContain(row.url) + expect(markdown).toContain(row.url) + } + } + } }) })