Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fallback to type when missing targetFile #1729

Merged
merged 1 commit into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});