2022-06-16 07:47:16 +00:00
|
|
|
import { RenovateConfig, getConfig } from '../../../test/util';
|
2023-02-20 14:58:49 +00:00
|
|
|
import type { PackageFile } from '../../modules/manager/types';
|
2022-08-02 13:06:37 +00:00
|
|
|
import {
|
|
|
|
getDepWarningsDashboard,
|
2022-09-12 09:08:45 +00:00
|
|
|
getDepWarningsOnboardingPR,
|
2022-08-02 13:06:37 +00:00
|
|
|
getDepWarningsPR,
|
|
|
|
getErrors,
|
|
|
|
getWarnings,
|
|
|
|
} from './errors-warnings';
|
2017-11-03 09:01:54 +00:00
|
|
|
|
2022-06-16 07:47:16 +00:00
|
|
|
describe('workers/repository/errors-warnings', () => {
|
2017-11-03 09:01:54 +00:00
|
|
|
describe('getWarnings()', () => {
|
2020-01-10 10:35:49 +00:00
|
|
|
let config: RenovateConfig;
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2017-11-03 09:01:54 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetAllMocks();
|
2020-01-10 10:35:49 +00:00
|
|
|
config = getConfig();
|
2017-11-03 09:01:54 +00:00
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2017-11-03 10:56:25 +00:00
|
|
|
it('returns warning text', () => {
|
2017-11-03 09:01:54 +00:00
|
|
|
config.warnings = [
|
|
|
|
{
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'foo',
|
2017-11-03 09:01:54 +00:00
|
|
|
message: 'Failed to look up dependency',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const res = getWarnings(config);
|
2021-11-07 15:34:42 +00:00
|
|
|
expect(res).toMatchInlineSnapshot(`
|
|
|
|
"
|
|
|
|
# Warnings (1)
|
|
|
|
|
|
|
|
Please correct - or verify that you can safely ignore - these warnings before you merge this PR.
|
|
|
|
|
|
|
|
- \`foo\`: Failed to look up dependency
|
|
|
|
|
|
|
|
---
|
|
|
|
"
|
|
|
|
`);
|
2017-11-03 09:01:54 +00:00
|
|
|
});
|
2022-06-27 20:35:40 +00:00
|
|
|
|
|
|
|
it('getWarning returns empty string', () => {
|
|
|
|
config.warnings = [];
|
|
|
|
const res = getWarnings(config);
|
|
|
|
expect(res).toBe('');
|
|
|
|
});
|
2017-11-03 09:01:54 +00:00
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2022-06-27 20:35:40 +00:00
|
|
|
describe('getDepWarningsPR()', () => {
|
2018-12-05 12:19:27 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetAllMocks();
|
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2022-09-12 09:08:45 +00:00
|
|
|
it('returns 2 pr warnings text dependencyDashboard true', () => {
|
|
|
|
const dependencyDashboard = true;
|
2023-02-20 14:58:49 +00:00
|
|
|
const packageFiles: Record<string, PackageFile[]> = {
|
2018-12-05 12:19:27 +00:00
|
|
|
npm: [
|
|
|
|
{
|
|
|
|
packageFile: 'package.json',
|
|
|
|
deps: [
|
|
|
|
{
|
2022-06-21 09:39:30 +00:00
|
|
|
warnings: [{ message: 'Warning 1', topic: '' }],
|
2018-12-05 12:19:27 +00:00
|
|
|
},
|
|
|
|
{},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
packageFile: 'backend/package.json',
|
|
|
|
deps: [
|
|
|
|
{
|
2022-06-21 09:39:30 +00:00
|
|
|
warnings: [{ message: 'Warning 1', topic: '' }],
|
2018-12-05 12:19:27 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
dockerfile: [
|
|
|
|
{
|
|
|
|
packageFile: 'Dockerfile',
|
|
|
|
deps: [
|
|
|
|
{
|
2022-06-21 09:39:30 +00:00
|
|
|
warnings: [{ message: 'Warning 2', topic: '' }],
|
2018-12-05 12:19:27 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2022-06-27 20:35:40 +00:00
|
|
|
|
2022-09-12 09:08:45 +00:00
|
|
|
const res = getDepWarningsPR(packageFiles, dependencyDashboard);
|
2021-11-07 15:34:42 +00:00
|
|
|
expect(res).toMatchInlineSnapshot(`
|
|
|
|
"
|
|
|
|
---
|
|
|
|
|
|
|
|
### ⚠ Dependency Lookup Warnings ⚠
|
|
|
|
|
2022-09-12 09:08:45 +00:00
|
|
|
Warnings were logged while processing this repo. Please check the Dependency Dashboard for more information.
|
2021-11-07 15:34:42 +00:00
|
|
|
|
2022-09-12 09:08:45 +00:00
|
|
|
"
|
|
|
|
`);
|
|
|
|
});
|
2021-11-07 15:34:42 +00:00
|
|
|
|
2022-09-12 09:08:45 +00:00
|
|
|
it('returns 2 pr warnings text dependencyDashboard false', () => {
|
|
|
|
const dependencyDashboard = false;
|
2023-02-20 14:58:49 +00:00
|
|
|
const packageFiles: Record<string, PackageFile[]> = {
|
2022-09-12 09:08:45 +00:00
|
|
|
npm: [
|
|
|
|
{
|
|
|
|
packageFile: 'package.json',
|
|
|
|
deps: [
|
|
|
|
{
|
|
|
|
warnings: [{ message: 'Warning 1', topic: '' }],
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
packageFile: 'backend/package.json',
|
|
|
|
deps: [
|
|
|
|
{
|
|
|
|
warnings: [{ message: 'Warning 1', topic: '' }],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
dockerfile: [
|
|
|
|
{
|
|
|
|
packageFile: 'Dockerfile',
|
|
|
|
deps: [
|
|
|
|
{
|
|
|
|
warnings: [{ message: 'Warning 2', topic: '' }],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const res = getDepWarningsPR(packageFiles, dependencyDashboard);
|
|
|
|
expect(res).toMatchInlineSnapshot(`
|
|
|
|
"
|
|
|
|
---
|
|
|
|
|
|
|
|
### ⚠ Dependency Lookup Warnings ⚠
|
|
|
|
|
|
|
|
Warnings were logged while processing this repo. Please check the logs for more information.
|
2021-11-07 15:34:42 +00:00
|
|
|
|
|
|
|
"
|
|
|
|
`);
|
2018-12-05 12:19:27 +00:00
|
|
|
});
|
2022-06-27 20:35:40 +00:00
|
|
|
|
|
|
|
it('PR warning returns empty string', () => {
|
2023-02-20 14:58:49 +00:00
|
|
|
const packageFiles: Record<string, PackageFile[]> = {};
|
2022-06-27 20:35:40 +00:00
|
|
|
const res = getDepWarningsPR(packageFiles);
|
|
|
|
expect(res).toBe('');
|
|
|
|
});
|
2018-12-05 12:19:27 +00:00
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2022-08-02 13:06:37 +00:00
|
|
|
describe('getDepWarningsDashboard()', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetAllMocks();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns dependency dashboard warning text', () => {
|
2023-06-14 15:13:52 +00:00
|
|
|
const config: RenovateConfig = {};
|
2023-02-20 14:58:49 +00:00
|
|
|
const packageFiles: Record<string, PackageFile[]> = {
|
2022-08-02 13:06:37 +00:00
|
|
|
npm: [
|
|
|
|
{
|
|
|
|
packageFile: 'package.json',
|
|
|
|
deps: [
|
|
|
|
{
|
|
|
|
warnings: [{ message: 'dependency-1', topic: '' }],
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
packageFile: 'backend/package.json',
|
|
|
|
deps: [
|
|
|
|
{
|
|
|
|
warnings: [{ message: 'dependency-1', topic: '' }],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
dockerfile: [
|
|
|
|
{
|
|
|
|
packageFile: 'Dockerfile',
|
|
|
|
deps: [
|
|
|
|
{
|
|
|
|
warnings: [{ message: 'dependency-2', topic: '' }],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2023-06-14 15:13:52 +00:00
|
|
|
const res = getDepWarningsDashboard(packageFiles, config);
|
2022-08-02 13:06:37 +00:00
|
|
|
expect(res).toMatchInlineSnapshot(`
|
|
|
|
"
|
|
|
|
---
|
|
|
|
|
|
|
|
### ⚠ Dependency Lookup Warnings ⚠
|
|
|
|
|
|
|
|
- Renovate failed to look up the following dependencies: \`dependency-1\`, \`dependency-2\`.
|
|
|
|
|
|
|
|
Files affected: \`package.json\`, \`backend/package.json\`, \`Dockerfile\`
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
"
|
|
|
|
`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('dependency dashboard warning returns empty string', () => {
|
2023-06-14 15:13:52 +00:00
|
|
|
const config: RenovateConfig = {};
|
2023-02-20 14:58:49 +00:00
|
|
|
const packageFiles: Record<string, PackageFile[]> = {};
|
2023-06-14 15:13:52 +00:00
|
|
|
const res = getDepWarningsDashboard(packageFiles, config);
|
|
|
|
expect(res).toBe('');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('suppress notifications contains dependencyLookupWarnings flag then return empty string', () => {
|
|
|
|
const config: RenovateConfig = {
|
|
|
|
suppressNotifications: ['dependencyLookupWarnings'],
|
|
|
|
};
|
|
|
|
const packageFiles: Record<string, PackageFile[]> = {};
|
|
|
|
const res = getDepWarningsDashboard(packageFiles, config);
|
2022-08-02 13:06:37 +00:00
|
|
|
expect(res).toBe('');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-11-03 09:01:54 +00:00
|
|
|
describe('getErrors()', () => {
|
2020-01-10 10:35:49 +00:00
|
|
|
let config: RenovateConfig;
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2017-11-03 09:01:54 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetAllMocks();
|
2020-01-10 10:35:49 +00:00
|
|
|
config = getConfig();
|
2017-11-03 09:01:54 +00:00
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2017-11-03 10:56:25 +00:00
|
|
|
it('returns error text', () => {
|
2017-11-03 09:01:54 +00:00
|
|
|
config.errors = [
|
|
|
|
{
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'renovate.json',
|
2017-11-03 09:01:54 +00:00
|
|
|
message: 'Failed to parse',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const res = getErrors(config);
|
2021-11-07 15:34:42 +00:00
|
|
|
expect(res).toMatchInlineSnapshot(`
|
|
|
|
"
|
|
|
|
# Errors (1)
|
|
|
|
|
|
|
|
Renovate has found errors that you should fix (in this branch) before finishing this PR.
|
|
|
|
|
|
|
|
- \`renovate.json\`: Failed to parse
|
|
|
|
|
|
|
|
---
|
|
|
|
"
|
|
|
|
`);
|
2017-11-03 09:01:54 +00:00
|
|
|
});
|
2022-06-27 20:35:40 +00:00
|
|
|
|
|
|
|
it('getError returns empty string', () => {
|
|
|
|
config.errors = [];
|
|
|
|
const res = getErrors(config);
|
|
|
|
expect(res).toBe('');
|
|
|
|
});
|
2017-11-03 09:01:54 +00:00
|
|
|
});
|
2022-09-12 09:08:45 +00:00
|
|
|
|
|
|
|
describe('getDepWarningsOnboardingPR()', () => {
|
|
|
|
it('returns onboarding warning text', () => {
|
2023-02-20 14:58:49 +00:00
|
|
|
const packageFiles: Record<string, PackageFile[]> = {
|
2022-09-12 09:08:45 +00:00
|
|
|
npm: [
|
|
|
|
{
|
|
|
|
packageFile: 'package.json',
|
|
|
|
deps: [
|
|
|
|
{
|
|
|
|
warnings: [{ message: 'Warning 1', topic: '' }],
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
packageFile: 'backend/package.json',
|
|
|
|
deps: [
|
|
|
|
{
|
|
|
|
warnings: [{ message: 'Warning 1', topic: '' }],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
dockerfile: [
|
|
|
|
{
|
|
|
|
packageFile: 'Dockerfile',
|
|
|
|
deps: [
|
|
|
|
{
|
|
|
|
warnings: [{ message: 'Warning 2', topic: '' }],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const res = getDepWarningsOnboardingPR(packageFiles);
|
|
|
|
expect(res).toMatchInlineSnapshot(`
|
|
|
|
"
|
|
|
|
---
|
|
|
|
|
|
|
|
### ⚠ Dependency Lookup Warnings ⚠
|
|
|
|
|
|
|
|
Please correct - or verify that you can safely ignore - these lookup failures before you merge this PR.
|
|
|
|
|
|
|
|
- \`Warning 1\`
|
|
|
|
- \`Warning 2\`
|
|
|
|
|
|
|
|
Files affected: \`package.json\`, \`backend/package.json\`, \`Dockerfile\`
|
|
|
|
|
|
|
|
"
|
|
|
|
`);
|
|
|
|
});
|
|
|
|
});
|
2017-11-03 09:01:54 +00:00
|
|
|
});
|