Skip to content

Commit

Permalink
feat: fallback to type when missing targetFile
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed Mar 15, 2021
1 parent 183f676 commit d22eca8
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 d22eca8

Please sign in to comment.