2020-03-05 20:57:24 +00:00
|
|
|
import { getConfig } from './defaults';
|
2018-04-05 20:51:44 +00:00
|
|
|
|
2020-03-05 20:57:24 +00:00
|
|
|
jest.mock('../datasource/npm');
|
2019-10-08 06:52:18 +00:00
|
|
|
try {
|
|
|
|
jest.mock('../../config.js');
|
|
|
|
} catch (err) {
|
|
|
|
// file does not exist
|
|
|
|
}
|
2019-08-15 04:30:16 +00:00
|
|
|
|
2019-08-23 13:46:31 +00:00
|
|
|
const defaultConfig = getConfig();
|
|
|
|
|
2021-08-18 05:46:56 +00:00
|
|
|
describe('config/index', () => {
|
2017-07-01 04:44:41 +00:00
|
|
|
describe('mergeChildConfig(parentConfig, childConfig)', () => {
|
2020-03-07 10:27:10 +00:00
|
|
|
it('merges', async () => {
|
2017-08-03 06:01:20 +00:00
|
|
|
const parentConfig = { ...defaultConfig };
|
2017-07-01 04:44:41 +00:00
|
|
|
const childConfig = {
|
|
|
|
foo: 'bar',
|
feat: rangeStrategy (#1954)
This PR replaces the existing `pinVersions`, `upgradeInRange` and `versionStrategy` settings with a single one: `rangeStrategy`.
Previously:
- `pinVersions` could be `true` or `false`, but defaulted to `null`, which meant that Renovate would decide. `true` meant that Renovate would replace existing ranges like `^1.0.0` with an exact/pinned version such as `1.2.0`.
- `upgradeInRange` could be true or false, default to false. If `true`, it would mean Renovate would replace an existing range like `^1.0.0` with something like `^1.2.0`
- `versionStrategy` could be `replace` or `widen` and was mainly used for `peerDependencies` to widen existing ranges, e.g. from `^1.0.0` to `^1.0.0 || ^2.0.0`
It was possible to set conflicting settings, e.g. configuring `pinVersions=true` and `upgradeInRange=true`.
Now, we combine them into a single setting: `rangeStrategy`:
- `auto` = Renovate decides (this will be done on a manager-by-manager basis)
- `pin` = convert ranges to exact versions
- `bump` = same as `upgradeInRange` previously, e.g. bump the range even if the new version satisifies the existing range
- `replace` = Same as pinVersions === false && upgradeInRange === false, i.e. only replace the range if the new version falls outside it
- `widen` = Same as previous versionStrategy==='widen'
2018-05-17 05:16:13 +00:00
|
|
|
rangeStrategy: 'replace',
|
2017-07-01 04:44:41 +00:00
|
|
|
lockFileMaintenance: {
|
2017-08-02 14:14:09 +00:00
|
|
|
schedule: ['on monday'],
|
2017-07-01 04:44:41 +00:00
|
|
|
},
|
|
|
|
};
|
2020-03-07 10:27:10 +00:00
|
|
|
const configParser = await import('./index');
|
2017-07-01 04:44:41 +00:00
|
|
|
const config = configParser.mergeChildConfig(parentConfig, childConfig);
|
2021-11-08 12:16:58 +00:00
|
|
|
expect(config.foo).toBe('bar');
|
|
|
|
expect(config.rangeStrategy).toBe('replace');
|
2017-08-02 14:14:09 +00:00
|
|
|
expect(config.lockFileMaintenance.schedule).toEqual(['on monday']);
|
2017-07-01 04:44:41 +00:00
|
|
|
expect(config.lockFileMaintenance).toMatchSnapshot();
|
|
|
|
});
|
2020-03-07 10:27:10 +00:00
|
|
|
it('merges packageRules', async () => {
|
2017-08-06 04:41:45 +00:00
|
|
|
const parentConfig = { ...defaultConfig };
|
|
|
|
Object.assign(parentConfig, {
|
|
|
|
packageRules: [{ a: 1 }, { a: 2 }],
|
|
|
|
});
|
|
|
|
const childConfig = {
|
|
|
|
packageRules: [{ a: 3 }, { a: 4 }],
|
|
|
|
};
|
2020-03-07 10:27:10 +00:00
|
|
|
const configParser = await import('./index');
|
2017-08-06 04:41:45 +00:00
|
|
|
const config = configParser.mergeChildConfig(parentConfig, childConfig);
|
2020-04-12 16:09:36 +00:00
|
|
|
expect(config.packageRules.map((rule) => rule.a)).toMatchObject([
|
2021-05-17 08:06:24 +00:00
|
|
|
1, 2, 3, 4,
|
2017-08-06 04:41:45 +00:00
|
|
|
]);
|
|
|
|
});
|
2020-10-27 08:01:48 +00:00
|
|
|
it('merges constraints', async () => {
|
|
|
|
const parentConfig = { ...defaultConfig };
|
|
|
|
Object.assign(parentConfig, {
|
|
|
|
constraints: {
|
|
|
|
node: '>=12',
|
|
|
|
npm: '^6.0.0',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const childConfig = {
|
|
|
|
constraints: {
|
|
|
|
node: '<15',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const configParser = await import('./index');
|
|
|
|
const config = configParser.mergeChildConfig(parentConfig, childConfig);
|
|
|
|
expect(config.constraints).toMatchSnapshot();
|
2021-11-08 12:16:58 +00:00
|
|
|
expect(config.constraints.node).toBe('<15');
|
2020-10-27 08:01:48 +00:00
|
|
|
});
|
2020-03-07 10:27:10 +00:00
|
|
|
it('handles null parent packageRules', async () => {
|
2017-08-07 08:39:32 +00:00
|
|
|
const parentConfig = { ...defaultConfig };
|
|
|
|
Object.assign(parentConfig, {
|
|
|
|
packageRules: null,
|
|
|
|
});
|
|
|
|
const childConfig = {
|
|
|
|
packageRules: [{ a: 3 }, { a: 4 }],
|
|
|
|
};
|
2020-03-07 10:27:10 +00:00
|
|
|
const configParser = await import('./index');
|
2017-08-07 08:39:32 +00:00
|
|
|
const config = configParser.mergeChildConfig(parentConfig, childConfig);
|
|
|
|
expect(config.packageRules).toHaveLength(2);
|
|
|
|
});
|
2020-03-07 10:27:10 +00:00
|
|
|
it('handles null child packageRules', async () => {
|
2017-08-11 06:03:18 +00:00
|
|
|
const parentConfig = { ...defaultConfig };
|
|
|
|
parentConfig.packageRules = [{ a: 3 }, { a: 4 }];
|
2020-03-07 10:27:10 +00:00
|
|
|
const configParser = await import('./index');
|
2017-08-11 06:03:18 +00:00
|
|
|
const config = configParser.mergeChildConfig(parentConfig, {});
|
|
|
|
expect(config.packageRules).toHaveLength(2);
|
|
|
|
});
|
2020-03-07 10:27:10 +00:00
|
|
|
it('handles undefined childConfig', async () => {
|
2017-09-13 18:29:20 +00:00
|
|
|
const parentConfig = { ...defaultConfig };
|
2020-03-07 10:27:10 +00:00
|
|
|
const configParser = await import('./index');
|
2017-09-13 18:29:20 +00:00
|
|
|
const config = configParser.mergeChildConfig(parentConfig, undefined);
|
|
|
|
expect(config).toMatchObject(parentConfig);
|
|
|
|
});
|
2020-03-07 10:27:10 +00:00
|
|
|
|
|
|
|
it('getManagerConfig()', async () => {
|
|
|
|
const parentConfig = { ...defaultConfig };
|
|
|
|
const configParser = await import('./index');
|
|
|
|
const config = configParser.getManagerConfig(parentConfig, 'npm');
|
2020-05-18 12:33:44 +00:00
|
|
|
expect(config).toContainEntries([
|
|
|
|
['fileMatch', ['(^|/)package.json$']],
|
|
|
|
['rollbackPrs', true],
|
|
|
|
]);
|
2020-03-07 10:27:10 +00:00
|
|
|
expect(
|
|
|
|
configParser.getManagerConfig(parentConfig, 'html')
|
2020-05-18 12:33:44 +00:00
|
|
|
).toContainEntries([['fileMatch', ['\\.html?$']]]);
|
2020-03-07 10:27:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('filterConfig()', async () => {
|
|
|
|
const parentConfig = { ...defaultConfig };
|
|
|
|
const configParser = await import('./index');
|
|
|
|
const config = configParser.filterConfig(parentConfig, 'pr');
|
2020-05-18 12:33:44 +00:00
|
|
|
expect(config).toBeObject();
|
2020-03-07 10:27:10 +00:00
|
|
|
});
|
2017-07-01 04:44:41 +00:00
|
|
|
});
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|