2023-02-28 10:16:33 +00:00
|
|
|
import is from '@sindresorhus/is';
|
2021-08-18 05:46:56 +00:00
|
|
|
import { RenovateConfig, getConfig } from '../../../../test/util';
|
2020-05-01 16:03:48 +00:00
|
|
|
import { flattenUpdates } from './flatten';
|
2020-01-10 10:35:49 +00:00
|
|
|
|
2022-12-17 15:51:59 +00:00
|
|
|
jest.mock('../../../util/git/semantic');
|
|
|
|
|
2020-01-10 10:35:49 +00:00
|
|
|
let config: RenovateConfig;
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2018-05-09 06:03:59 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetAllMocks();
|
2020-01-10 10:35:49 +00:00
|
|
|
config = getConfig();
|
2018-05-09 06:03:59 +00:00
|
|
|
config.errors = [];
|
|
|
|
config.warnings = [];
|
|
|
|
});
|
|
|
|
|
2021-08-18 05:46:56 +00:00
|
|
|
describe('workers/repository/updates/flatten', () => {
|
2018-05-09 06:03:59 +00:00
|
|
|
describe('flattenUpdates()', () => {
|
2020-04-09 13:44:23 +00:00
|
|
|
it('flattens', async () => {
|
2022-06-21 09:39:30 +00:00
|
|
|
// TODO #7154
|
|
|
|
config.lockFileMaintenance!.enabled = true;
|
2018-07-06 04:43:02 +00:00
|
|
|
config.packageRules = [
|
|
|
|
{
|
2021-01-29 10:43:42 +00:00
|
|
|
matchUpdateTypes: ['minor'],
|
2018-07-06 04:43:02 +00:00
|
|
|
automerge: true,
|
|
|
|
},
|
2018-09-07 07:57:29 +00:00
|
|
|
{
|
2021-01-29 10:43:42 +00:00
|
|
|
matchPaths: ['frontend/package.json'],
|
2018-09-07 07:57:29 +00:00
|
|
|
lockFileMaintenance: {
|
|
|
|
enabled: false,
|
|
|
|
},
|
|
|
|
},
|
2018-07-06 04:43:02 +00:00
|
|
|
];
|
2021-03-01 07:59:57 +00:00
|
|
|
config.remediations = {
|
|
|
|
'package-lock.json': [
|
|
|
|
{
|
|
|
|
datasoource: 'npm',
|
|
|
|
depName: 'foo',
|
|
|
|
currentVersion: '1.2.0',
|
|
|
|
newVersion: '1.3.0',
|
|
|
|
prBodyNotes: '',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2018-05-09 06:03:59 +00:00
|
|
|
const packageFiles = {
|
|
|
|
npm: [
|
|
|
|
{
|
2018-09-07 07:13:30 +00:00
|
|
|
packageFile: 'package.json',
|
2021-03-01 07:59:57 +00:00
|
|
|
lockFiles: ['package-lock.json'],
|
2018-05-09 06:03:59 +00:00
|
|
|
deps: [
|
2021-05-08 13:57:14 +00:00
|
|
|
{
|
|
|
|
depName: '@org/a',
|
|
|
|
updates: [
|
|
|
|
{
|
|
|
|
newValue: '1.0.0',
|
|
|
|
sourceUrl: 'https://github.com/org/repo',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
depName: 'foo',
|
|
|
|
updates: [
|
|
|
|
{
|
|
|
|
newValue: '2.0.0',
|
|
|
|
sourceUrl: 'https://github.com/org/repo',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2019-05-24 13:01:07 +00:00
|
|
|
{
|
|
|
|
updateTypes: ['pin'],
|
|
|
|
updates: [{ newValue: '2.0.0' }],
|
|
|
|
},
|
2021-11-12 08:10:52 +00:00
|
|
|
{
|
|
|
|
depName: 'abc',
|
|
|
|
updates: [
|
|
|
|
{
|
|
|
|
newName: 'def',
|
|
|
|
newValue: '2.0.0',
|
|
|
|
updateType: 'replacement',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2018-05-09 06:03:59 +00:00
|
|
|
],
|
|
|
|
},
|
2018-09-07 07:57:29 +00:00
|
|
|
{
|
|
|
|
packageFile: 'backend/package.json',
|
2021-05-08 13:57:14 +00:00
|
|
|
deps: [
|
|
|
|
{
|
|
|
|
depName: 'bar',
|
|
|
|
updates: [{ newValue: '3.0.0', sourceUrl: 3 }],
|
|
|
|
},
|
|
|
|
],
|
2018-09-07 07:57:29 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
packageFile: 'frontend/package.json',
|
|
|
|
deps: [{ depName: 'baz', updates: [{ newValue: '3.0.1' }] }],
|
|
|
|
},
|
2018-05-09 06:03:59 +00:00
|
|
|
],
|
2018-07-21 17:40:50 +00:00
|
|
|
dockerfile: [
|
2018-06-29 04:55:42 +00:00
|
|
|
{
|
|
|
|
packageFile: 'Dockerfile',
|
|
|
|
deps: [
|
|
|
|
{
|
|
|
|
depName: 'amd64/node',
|
2022-11-05 08:49:57 +00:00
|
|
|
language: 'docker',
|
2021-05-08 13:57:14 +00:00
|
|
|
sourceUrl: 'https://github.com/nodejs/node',
|
2018-06-29 04:55:42 +00:00
|
|
|
updates: [{ newValue: '10.0.1' }],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2018-08-16 13:46:19 +00:00
|
|
|
{
|
|
|
|
packageFile: 'Dockerfile',
|
|
|
|
deps: [
|
|
|
|
{
|
|
|
|
depName: 'calico/node',
|
2022-11-05 08:49:57 +00:00
|
|
|
language: 'docker',
|
2021-05-08 13:57:14 +00:00
|
|
|
sourceUrl: 'https://calico.com',
|
2020-08-26 09:27:09 +00:00
|
|
|
updates: [{ newValue: '3.2.0', updateType: 'minor' }],
|
2018-08-16 13:46:19 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2018-06-29 04:55:42 +00:00
|
|
|
],
|
2021-02-18 15:27:47 +00:00
|
|
|
gomod: [
|
|
|
|
{
|
|
|
|
packageFile: 'go.mod',
|
|
|
|
deps: [
|
|
|
|
{
|
|
|
|
depName: 'github.com/Parallels/docker-machine-parallels',
|
|
|
|
updates: [{ newValue: '1.3.0' }],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
depName: 'gopkg.in/yaml.v2',
|
|
|
|
updates: [{ newValue: '2.2.8', updateType: 'minor' }],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
depName: 'gopkg.in/warnings.v0',
|
|
|
|
updates: [{ newValue: '0.1.3' }],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
depName: 'github.com/blang/semver',
|
|
|
|
updates: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2018-05-09 06:03:59 +00:00
|
|
|
};
|
2020-04-09 13:44:23 +00:00
|
|
|
const res = await flattenUpdates(config, packageFiles);
|
2021-11-12 08:10:52 +00:00
|
|
|
expect(res).toHaveLength(14);
|
2023-02-28 10:16:33 +00:00
|
|
|
expect(
|
|
|
|
res.every(
|
|
|
|
(upgrade) =>
|
|
|
|
upgrade.isLockFileMaintenance ||
|
|
|
|
upgrade.isRemediation ||
|
|
|
|
is.number(upgrade.depIndex)
|
|
|
|
)
|
|
|
|
).toBeTrue();
|
2022-01-21 12:03:06 +00:00
|
|
|
expect(
|
|
|
|
res.filter((update) => update.sourceRepoSlug)[0].sourceRepoSlug
|
|
|
|
).toBe('org-repo');
|
|
|
|
expect(res.filter((update) => update.sourceRepo)[0].sourceRepo).toBe(
|
|
|
|
'org/repo'
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
res.filter((update) => update.sourceRepoOrg)[0].sourceRepoOrg
|
|
|
|
).toBe('org');
|
|
|
|
expect(
|
|
|
|
res.filter((update) => update.sourceRepoName)[0].sourceRepoName
|
|
|
|
).toBe('repo');
|
|
|
|
expect(
|
|
|
|
res.filter((update) => update.sourceRepoSlug)[1].sourceRepoSlug
|
|
|
|
).toBe('org-repo');
|
|
|
|
expect(res.filter((update) => update.sourceRepo)[1].sourceRepo).toBe(
|
|
|
|
'org/repo'
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
res.filter((update) => update.sourceRepoOrg)[1].sourceRepoOrg
|
|
|
|
).toBe('org');
|
|
|
|
expect(
|
|
|
|
res.filter((update) => update.sourceRepoName)[1].sourceRepoName
|
|
|
|
).toBe('repo');
|
|
|
|
expect(
|
|
|
|
res.filter((update) => update.sourceRepoSlug)[2].sourceRepoSlug
|
|
|
|
).toBe('nodejs-node');
|
|
|
|
expect(res.filter((update) => update.sourceRepo)[2].sourceRepo).toBe(
|
|
|
|
'nodejs/node'
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
res.filter((update) => update.sourceRepoOrg)[2].sourceRepoOrg
|
|
|
|
).toBe('nodejs');
|
|
|
|
expect(
|
|
|
|
res.filter((update) => update.sourceRepoName)[2].sourceRepoName
|
|
|
|
).toBe('node');
|
2018-09-07 07:57:29 +00:00
|
|
|
expect(
|
2022-02-05 06:35:46 +00:00
|
|
|
res.filter(
|
|
|
|
(r) =>
|
|
|
|
r.updateType === 'lockFileMaintenance' && r.isLockFileMaintenance
|
|
|
|
)
|
2018-09-07 07:57:29 +00:00
|
|
|
).toHaveLength(2);
|
2021-03-01 07:59:57 +00:00
|
|
|
expect(res.filter((r) => r.isVulnerabilityAlert)).toHaveLength(1);
|
2018-05-09 06:03:59 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|