diff --git a/packages/snyk-fix/src/lib/output-formatters/format-unresolved-item.ts b/packages/snyk-fix/src/lib/output-formatters/format-unresolved-item.ts index 375ecdafc6..5e9d397007 100644 --- a/packages/snyk-fix/src/lib/output-formatters/format-unresolved-item.ts +++ b/packages/snyk-fix/src/lib/output-formatters/format-unresolved-item.ts @@ -6,7 +6,10 @@ export function formatUnresolved( entity: EntityToFix, userMessage: string, ): string { - return `${PADDING_SPACE}${entity.scanResult.identity.targetFile}\n${PADDING_SPACE}${chalk.red( + const name = + entity.scanResult.identity.targetFile || + `${entity.scanResult.identity.type} project`; + return `${PADDING_SPACE}${name}\n${PADDING_SPACE}${chalk.red( '✖', )} ${chalk.red(userMessage)}`; } diff --git a/packages/snyk-fix/test/unit/lib/output-formatters/__snapshots__/format-unresolved-item.spec.ts.snap b/packages/snyk-fix/test/unit/lib/output-formatters/__snapshots__/format-unresolved-item.spec.ts.snap index b9f0980e21..823198b8d4 100644 --- a/packages/snyk-fix/test/unit/lib/output-formatters/__snapshots__/format-unresolved-item.spec.ts.snap +++ b/packages/snyk-fix/test/unit/lib/output-formatters/__snapshots__/format-unresolved-item.spec.ts.snap @@ -1,6 +1,11 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`format unresolved item successful item & changes formatted 1`] = ` +exports[`format unresolved item formats ok when missing targetFile 1`] = ` +" npm project + ✖ Failed to process item" +`; + +exports[`format unresolved item formats unresolved as expected by default 1`] = ` " requirements.txt ✖ Failed to process item" `; diff --git a/packages/snyk-fix/test/unit/lib/output-formatters/format-unresolved-item.spec.ts b/packages/snyk-fix/test/unit/lib/output-formatters/format-unresolved-item.spec.ts index 77576b55fd..c7c29d0fcc 100644 --- a/packages/snyk-fix/test/unit/lib/output-formatters/format-unresolved-item.spec.ts +++ b/packages/snyk-fix/test/unit/lib/output-formatters/format-unresolved-item.spec.ts @@ -3,7 +3,7 @@ import { formatUnresolved } from '../../../../src/lib/output-formatters/format-u import { generateEntityToFix } from '../../../helpers/generate-entity-to-fix'; describe('format unresolved item', () => { - it('successful item & changes formatted', async () => { + it('formats unresolved as expected by default', async () => { const entity = generateEntityToFix( 'pip', 'requirements.txt', @@ -12,4 +12,14 @@ describe('format unresolved item', () => { const res = await formatUnresolved(entity, 'Failed to process item'); expect(stripAnsi(res)).toMatchSnapshot(); }); + + it('formats ok when missing targetFile', async () => { + const entity = generateEntityToFix( + 'npm', + undefined as any, + JSON.stringify({}), + ); + const res = await formatUnresolved(entity, 'Failed to process item'); + expect(stripAnsi(res)).toMatchSnapshot(); + }); });