Skip to content

Commit

Permalink
Merge pull request #1729 from snyk/feat/fall-back-to-project-type
Browse files Browse the repository at this point in the history
feat: fallback to type when missing targetFile
  • Loading branch information
lili2311 authored Mar 16, 2021
2 parents 03226b6 + d22eca8 commit 1014be3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`;
}
Original file line number Diff line number Diff line change
@@ -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"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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();
});
});

0 comments on commit 1014be3

Please sign in to comment.