2020-01-30 06:07:56 +00:00
|
|
|
import getArgv from './config/_fixtures/argv';
|
2019-08-23 13:46:31 +00:00
|
|
|
import { getConfig } from '../../lib/config/defaults';
|
|
|
|
import * as _npm from '../../lib/datasource/npm';
|
|
|
|
import presetDefaults from './npm/_fixtures/renovate-config-default.json';
|
2018-04-05 20:51:44 +00:00
|
|
|
|
2019-08-15 04:30:16 +00:00
|
|
|
jest.mock('../../lib/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 npm: any = _npm;
|
|
|
|
const defaultConfig = getConfig();
|
|
|
|
|
2018-07-29 14:04:00 +00:00
|
|
|
npm.getPkgReleases = jest.fn(() => ({
|
2018-04-05 20:51:44 +00:00
|
|
|
'renovate-config':
|
|
|
|
presetDefaults.versions[presetDefaults['dist-tags'].latest][
|
|
|
|
'renovate-config'
|
|
|
|
],
|
|
|
|
}));
|
2017-01-20 13:03:18 +00:00
|
|
|
|
|
|
|
describe('config/index', () => {
|
|
|
|
describe('.parseConfigs(env, defaultArgv)', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
let configParser: typeof import('../../lib/config');
|
|
|
|
let defaultArgv: string[];
|
2017-02-09 04:30:00 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetModules();
|
2019-08-23 13:46:31 +00:00
|
|
|
configParser = require('../../lib/config/index');
|
2020-01-30 06:07:56 +00:00
|
|
|
defaultArgv = getArgv();
|
2018-04-09 04:07:05 +00:00
|
|
|
jest.mock('delay');
|
|
|
|
require('delay').mockImplementation(() => Promise.resolve());
|
2017-02-09 04:30:00 +00:00
|
|
|
});
|
2017-04-21 05:00:26 +00:00
|
|
|
it('supports token in env', async () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const env: NodeJS.ProcessEnv = { RENOVATE_TOKEN: 'abc' };
|
2017-07-15 04:47:20 +00:00
|
|
|
await configParser.parseConfigs(env, defaultArgv);
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
2017-04-21 05:00:26 +00:00
|
|
|
it('supports token in CLI options', async () => {
|
2019-01-22 17:17:59 +00:00
|
|
|
defaultArgv = defaultArgv.concat(['--token=abc', '--pr-footer=custom']);
|
2019-08-23 13:46:31 +00:00
|
|
|
const env: NodeJS.ProcessEnv = {};
|
2017-07-15 04:47:20 +00:00
|
|
|
await configParser.parseConfigs(env, defaultArgv);
|
2018-06-21 08:23:59 +00:00
|
|
|
});
|
|
|
|
it('supports forceCli', async () => {
|
|
|
|
defaultArgv = defaultArgv.concat(['--force-cli=true']);
|
2019-08-23 13:46:31 +00:00
|
|
|
const env: NodeJS.ProcessEnv = { RENOVATE_TOKEN: 'abc' };
|
2018-06-21 08:23:59 +00:00
|
|
|
await configParser.parseConfigs(env, defaultArgv);
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
2018-08-29 05:30:03 +00:00
|
|
|
it('supports Bitbucket username/passwod', async () => {
|
|
|
|
defaultArgv = defaultArgv.concat([
|
|
|
|
'--platform=bitbucket',
|
|
|
|
'--username=user',
|
|
|
|
'--password=pass',
|
|
|
|
]);
|
2019-08-23 13:46:31 +00:00
|
|
|
const env: NodeJS.ProcessEnv = {};
|
2018-08-29 05:30:03 +00:00
|
|
|
await configParser.parseConfigs(env, defaultArgv);
|
|
|
|
});
|
2020-01-01 09:23:55 +00:00
|
|
|
it('massages trailing slash into endpoint', async () => {
|
|
|
|
defaultArgv = defaultArgv.concat([
|
|
|
|
'--endpoint=https://github.renovatebot.com/api/v3',
|
|
|
|
]);
|
|
|
|
const env: NodeJS.ProcessEnv = {};
|
|
|
|
const parsed = await configParser.parseConfigs(env, defaultArgv);
|
|
|
|
expect(parsed.endpoint).toEqual('https://github.renovatebot.com/api/v3/');
|
|
|
|
});
|
2017-06-22 07:03:36 +00:00
|
|
|
});
|
2017-07-01 04:44:41 +00:00
|
|
|
describe('mergeChildConfig(parentConfig, childConfig)', () => {
|
|
|
|
it('merges', () => {
|
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
|
|
|
},
|
|
|
|
};
|
2019-08-23 13:46:31 +00:00
|
|
|
const configParser = require('../../lib/config/index');
|
2017-07-01 04:44:41 +00:00
|
|
|
const config = configParser.mergeChildConfig(parentConfig, childConfig);
|
|
|
|
expect(config.foo).toEqual('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
|
|
|
expect(config.rangeStrategy).toEqual('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();
|
|
|
|
});
|
2017-08-06 04:41:45 +00:00
|
|
|
it('merges packageRules', () => {
|
|
|
|
const parentConfig = { ...defaultConfig };
|
|
|
|
Object.assign(parentConfig, {
|
|
|
|
packageRules: [{ a: 1 }, { a: 2 }],
|
|
|
|
});
|
|
|
|
const childConfig = {
|
|
|
|
packageRules: [{ a: 3 }, { a: 4 }],
|
|
|
|
};
|
2019-08-23 13:46:31 +00:00
|
|
|
const configParser = require('../../lib/config/index');
|
2017-08-06 04:41:45 +00:00
|
|
|
const config = configParser.mergeChildConfig(parentConfig, childConfig);
|
|
|
|
expect(config.packageRules.map(rule => rule.a)).toMatchObject([
|
|
|
|
1,
|
|
|
|
2,
|
2017-08-11 06:03:18 +00:00
|
|
|
3,
|
|
|
|
4,
|
2017-08-06 04:41:45 +00:00
|
|
|
]);
|
|
|
|
});
|
2017-08-11 06:03:18 +00:00
|
|
|
it('handles null parent packageRules', () => {
|
2017-08-07 08:39:32 +00:00
|
|
|
const parentConfig = { ...defaultConfig };
|
|
|
|
Object.assign(parentConfig, {
|
|
|
|
packageRules: null,
|
|
|
|
});
|
|
|
|
const childConfig = {
|
|
|
|
packageRules: [{ a: 3 }, { a: 4 }],
|
|
|
|
};
|
2019-08-23 13:46:31 +00:00
|
|
|
const configParser = require('../../lib/config/index');
|
2017-08-07 08:39:32 +00:00
|
|
|
const config = configParser.mergeChildConfig(parentConfig, childConfig);
|
|
|
|
expect(config.packageRules).toHaveLength(2);
|
|
|
|
});
|
2017-08-11 06:03:18 +00:00
|
|
|
it('handles null child packageRules', () => {
|
|
|
|
const parentConfig = { ...defaultConfig };
|
|
|
|
parentConfig.packageRules = [{ a: 3 }, { a: 4 }];
|
2019-08-23 13:46:31 +00:00
|
|
|
const configParser = require('../../lib/config/index');
|
2017-08-11 06:03:18 +00:00
|
|
|
const config = configParser.mergeChildConfig(parentConfig, {});
|
|
|
|
expect(config.packageRules).toHaveLength(2);
|
|
|
|
});
|
2017-09-13 18:29:20 +00:00
|
|
|
it('handles undefined childConfig', () => {
|
|
|
|
const parentConfig = { ...defaultConfig };
|
2019-08-23 13:46:31 +00:00
|
|
|
const configParser = require('../../lib/config/index');
|
2017-09-13 18:29:20 +00:00
|
|
|
const config = configParser.mergeChildConfig(parentConfig, undefined);
|
|
|
|
expect(config).toMatchObject(parentConfig);
|
|
|
|
});
|
2017-07-01 04:44:41 +00:00
|
|
|
});
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|