2020-05-01 16:03:48 +00:00
|
|
|
import { RenovateConfig } from '..';
|
2021-04-13 10:25:51 +00:00
|
|
|
import { getName, mocked } from '../../../test/util';
|
2020-05-01 16:03:48 +00:00
|
|
|
import presetIkatyang from './__fixtures__/renovate-config-ikatyang.json';
|
2021-01-29 09:54:55 +00:00
|
|
|
import * as _local from './local';
|
2020-02-27 13:19:58 +00:00
|
|
|
import * as _npm from './npm';
|
2021-04-19 13:31:38 +00:00
|
|
|
import {
|
|
|
|
PRESET_DEP_NOT_FOUND,
|
|
|
|
PRESET_NOT_FOUND,
|
|
|
|
PRESET_RENOVATE_CONFIG_NOT_FOUND,
|
|
|
|
} from './util';
|
2020-02-27 13:19:58 +00:00
|
|
|
import * as presets from '.';
|
2017-08-18 04:10:19 +00:00
|
|
|
|
2020-02-27 13:19:58 +00:00
|
|
|
jest.mock('./npm');
|
2020-04-28 12:33:01 +00:00
|
|
|
jest.mock('./github');
|
2021-01-29 09:54:55 +00:00
|
|
|
jest.mock('./local');
|
2019-08-15 04:30:16 +00:00
|
|
|
|
2020-05-09 07:04:39 +00:00
|
|
|
const npm = mocked(_npm);
|
2021-01-29 09:54:55 +00:00
|
|
|
const local = mocked(_local);
|
2019-08-23 13:46:31 +00:00
|
|
|
|
2020-05-09 07:04:39 +00:00
|
|
|
npm.getPreset = jest.fn(({ packageName, presetName }) => {
|
|
|
|
if (packageName === 'renovate-config-ikatyang') {
|
2018-07-30 06:08:28 +00:00
|
|
|
return presetIkatyang.versions[presetIkatyang['dist-tags'].latest][
|
|
|
|
'renovate-config'
|
|
|
|
][presetName];
|
2017-08-25 04:25:25 +00:00
|
|
|
}
|
2020-05-09 07:04:39 +00:00
|
|
|
if (packageName === 'renovate-config-notfound') {
|
2021-04-19 13:31:38 +00:00
|
|
|
throw new Error(PRESET_DEP_NOT_FOUND);
|
2017-08-19 05:31:36 +00:00
|
|
|
}
|
2020-05-09 07:04:39 +00:00
|
|
|
if (packageName === 'renovate-config-noconfig') {
|
2021-04-19 13:31:38 +00:00
|
|
|
throw new Error(PRESET_RENOVATE_CONFIG_NOT_FOUND);
|
2017-08-18 04:10:19 +00:00
|
|
|
}
|
2020-05-09 07:04:39 +00:00
|
|
|
if (packageName === 'renovate-config-throw') {
|
2017-08-18 04:10:19 +00:00
|
|
|
throw new Error('whoops');
|
|
|
|
}
|
2020-05-09 07:04:39 +00:00
|
|
|
if (packageName === 'renovate-config-wrongpreset') {
|
2021-04-19 13:31:38 +00:00
|
|
|
throw new Error(PRESET_NOT_FOUND);
|
2017-08-18 04:10:19 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
2021-04-13 10:25:51 +00:00
|
|
|
describe(getName(__filename), () => {
|
2017-08-18 04:10:19 +00:00
|
|
|
describe('resolvePreset', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
let config: RenovateConfig;
|
2017-08-18 04:10:19 +00:00
|
|
|
beforeEach(() => {
|
2017-11-08 05:44:03 +00:00
|
|
|
config = {};
|
2017-08-18 04:10:19 +00:00
|
|
|
});
|
|
|
|
it('returns same if no presets', async () => {
|
|
|
|
config.foo = 1;
|
|
|
|
config.extends = [];
|
|
|
|
const res = await presets.resolveConfigPresets(config);
|
|
|
|
expect(config).toMatchObject(res);
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
2017-12-18 08:39:52 +00:00
|
|
|
it('throws if invalid preset file', async () => {
|
|
|
|
config.foo = 1;
|
2018-07-30 06:08:28 +00:00
|
|
|
config.extends = ['notfound'];
|
2020-03-07 10:27:10 +00:00
|
|
|
let e: Error;
|
2017-12-18 08:39:52 +00:00
|
|
|
try {
|
|
|
|
await presets.resolveConfigPresets(config);
|
|
|
|
} catch (err) {
|
|
|
|
e = err;
|
|
|
|
}
|
|
|
|
expect(e).toBeDefined();
|
2021-04-01 13:50:17 +00:00
|
|
|
expect(e.location).toMatchSnapshot();
|
2017-12-18 08:39:52 +00:00
|
|
|
expect(e.validationError).toMatchSnapshot();
|
|
|
|
expect(e.validationMessage).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('throws if invalid preset', async () => {
|
2017-08-18 04:10:19 +00:00
|
|
|
config.foo = 1;
|
2018-07-30 06:08:28 +00:00
|
|
|
config.extends = ['wrongpreset:invalid-preset'];
|
2020-03-07 10:27:10 +00:00
|
|
|
let e: Error;
|
2017-12-18 08:39:52 +00:00
|
|
|
try {
|
|
|
|
await presets.resolveConfigPresets(config);
|
|
|
|
} catch (err) {
|
|
|
|
e = err;
|
|
|
|
}
|
|
|
|
expect(e).toBeDefined();
|
2021-04-01 13:50:17 +00:00
|
|
|
expect(e.location).toMatchSnapshot();
|
2017-12-18 08:39:52 +00:00
|
|
|
expect(e.validationError).toMatchSnapshot();
|
|
|
|
expect(e.validationMessage).toMatchSnapshot();
|
2017-08-18 04:10:19 +00:00
|
|
|
});
|
2020-03-07 10:27:10 +00:00
|
|
|
|
2021-03-20 23:03:10 +00:00
|
|
|
it('throws if path + invalid syntax', async () => {
|
|
|
|
config.foo = 1;
|
|
|
|
config.extends = ['github>user/repo//'];
|
|
|
|
let e: Error;
|
|
|
|
try {
|
|
|
|
await presets.resolveConfigPresets(config);
|
|
|
|
} catch (err) {
|
|
|
|
e = err;
|
|
|
|
}
|
|
|
|
expect(e).toBeDefined();
|
2021-04-01 13:50:17 +00:00
|
|
|
expect(e.location).toMatchSnapshot();
|
2021-03-20 23:03:10 +00:00
|
|
|
expect(e.validationError).toMatchSnapshot();
|
|
|
|
expect(e.validationMessage).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('throws if path + sub-preset', async () => {
|
|
|
|
config.foo = 1;
|
|
|
|
config.extends = ['github>user/repo//path:subpreset'];
|
|
|
|
let e: Error;
|
|
|
|
try {
|
|
|
|
await presets.resolveConfigPresets(config);
|
|
|
|
} catch (err) {
|
|
|
|
e = err;
|
|
|
|
}
|
|
|
|
expect(e).toBeDefined();
|
2021-04-01 13:50:17 +00:00
|
|
|
expect(e.location).toMatchSnapshot();
|
2021-03-20 23:03:10 +00:00
|
|
|
expect(e.validationError).toMatchSnapshot();
|
|
|
|
expect(e.validationMessage).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2020-03-07 10:27:10 +00:00
|
|
|
it('throws noconfig', async () => {
|
|
|
|
config.foo = 1;
|
|
|
|
config.extends = ['noconfig:base'];
|
|
|
|
let e: Error;
|
|
|
|
try {
|
|
|
|
await presets.resolveConfigPresets(config);
|
|
|
|
} catch (err) {
|
|
|
|
e = err;
|
|
|
|
}
|
|
|
|
expect(e).toBeDefined();
|
2021-04-01 13:50:17 +00:00
|
|
|
expect(e.location).toMatchSnapshot();
|
2020-03-07 10:27:10 +00:00
|
|
|
expect(e.validationError).toMatchSnapshot();
|
|
|
|
expect(e.validationMessage).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('throws throw', async () => {
|
|
|
|
config.foo = 1;
|
|
|
|
config.extends = ['throw:base'];
|
|
|
|
let e: Error;
|
|
|
|
try {
|
|
|
|
await presets.resolveConfigPresets(config);
|
|
|
|
} catch (err) {
|
|
|
|
e = err;
|
|
|
|
}
|
|
|
|
expect(e).toBeDefined();
|
2021-04-01 13:50:17 +00:00
|
|
|
expect(e.location).toMatchSnapshot();
|
2020-03-07 10:27:10 +00:00
|
|
|
expect(e.validationError).toMatchSnapshot();
|
|
|
|
expect(e.validationMessage).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2017-08-18 04:10:19 +00:00
|
|
|
it('works with valid', async () => {
|
|
|
|
config.foo = 1;
|
2019-05-24 13:01:07 +00:00
|
|
|
config.ignoreDeps = [];
|
2017-08-18 04:10:19 +00:00
|
|
|
config.extends = [':pinVersions'];
|
|
|
|
const res = await presets.resolveConfigPresets(config);
|
|
|
|
expect(res).toMatchSnapshot();
|
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(res.rangeStrategy).toEqual('pin');
|
2017-08-18 04:10:19 +00:00
|
|
|
});
|
2017-12-18 08:39:52 +00:00
|
|
|
it('throws if valid and invalid', async () => {
|
2017-08-18 04:10:19 +00:00
|
|
|
config.foo = 1;
|
2018-07-30 06:08:28 +00:00
|
|
|
config.extends = ['wrongpreset:invalid-preset', ':pinVersions'];
|
2020-03-07 10:27:10 +00:00
|
|
|
let e: Error;
|
2017-12-18 08:39:52 +00:00
|
|
|
try {
|
|
|
|
await presets.resolveConfigPresets(config);
|
|
|
|
} catch (err) {
|
|
|
|
e = err;
|
|
|
|
}
|
|
|
|
expect(e).toBeDefined();
|
2021-04-01 13:50:17 +00:00
|
|
|
expect(e.location).toMatchSnapshot();
|
2017-12-18 08:39:52 +00:00
|
|
|
expect(e.validationError).toMatchSnapshot();
|
|
|
|
expect(e.validationMessage).toMatchSnapshot();
|
2017-08-18 04:10:19 +00:00
|
|
|
});
|
|
|
|
it('combines two package alls', async () => {
|
|
|
|
config.extends = ['packages:eslint', 'packages:stylelint'];
|
|
|
|
const res = await presets.resolveConfigPresets(config);
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('resolves packageRule', async () => {
|
|
|
|
config.packageRules = [
|
|
|
|
{
|
|
|
|
extends: ['packages:eslint'],
|
|
|
|
groupName: 'eslint',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const res = await presets.resolveConfigPresets(config);
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
2017-08-24 10:39:23 +00:00
|
|
|
it('resolves eslint', async () => {
|
|
|
|
config.extends = ['packages:eslint'];
|
|
|
|
const res = await presets.resolveConfigPresets(config);
|
|
|
|
expect(res).toMatchSnapshot();
|
2021-04-03 05:18:25 +00:00
|
|
|
expect(res.matchPackagePrefixes).toHaveLength(2);
|
2017-08-24 10:39:23 +00:00
|
|
|
});
|
2017-08-18 04:10:19 +00:00
|
|
|
it('resolves linters', async () => {
|
|
|
|
config.extends = ['packages:linters'];
|
|
|
|
const res = await presets.resolveConfigPresets(config);
|
|
|
|
expect(res).toMatchSnapshot();
|
2021-01-29 10:43:42 +00:00
|
|
|
expect(res.matchPackageNames).toHaveLength(3);
|
2021-04-03 05:18:25 +00:00
|
|
|
expect(res.matchPackagePatterns).toHaveLength(1);
|
|
|
|
expect(res.matchPackagePrefixes).toHaveLength(4);
|
2017-08-18 04:10:19 +00:00
|
|
|
});
|
|
|
|
it('resolves nested groups', async () => {
|
|
|
|
config.extends = [':automergeLinters'];
|
|
|
|
const res = await presets.resolveConfigPresets(config);
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
const rule = res.packageRules[0];
|
2019-04-02 14:59:27 +00:00
|
|
|
expect(rule.automerge).toBe(true);
|
2021-01-29 10:43:42 +00:00
|
|
|
expect(rule.matchPackageNames).toHaveLength(3);
|
2021-04-03 05:18:25 +00:00
|
|
|
expect(rule.matchPackagePatterns).toHaveLength(1);
|
|
|
|
expect(rule.matchPackagePrefixes).toHaveLength(4);
|
2017-08-18 04:10:19 +00:00
|
|
|
});
|
2017-08-25 04:25:25 +00:00
|
|
|
it('migrates automerge in presets', async () => {
|
|
|
|
config.extends = ['ikatyang:library'];
|
|
|
|
const res = await presets.resolveConfigPresets(config);
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
expect(res.automerge).not.toBeDefined();
|
|
|
|
expect(res.minor.automerge).toBe(true);
|
|
|
|
});
|
2020-03-07 10:27:10 +00:00
|
|
|
|
|
|
|
it('ignores presets', async () => {
|
|
|
|
config.extends = ['config:base'];
|
2020-04-14 05:05:30 +00:00
|
|
|
const res = await presets.resolveConfigPresets(config, {}, [
|
|
|
|
'config:base',
|
|
|
|
]);
|
2020-03-07 10:27:10 +00:00
|
|
|
expect(config).toMatchObject(res);
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
2021-01-29 09:54:55 +00:00
|
|
|
|
|
|
|
it('resolves self-hosted presets without baseConfig', async () => {
|
|
|
|
config.extends = ['local>username/preset-repo'];
|
|
|
|
local.getPreset = jest.fn(({ packageName, presetName, baseConfig }) =>
|
|
|
|
Promise.resolve({ labels: ['self-hosted resolved'] })
|
|
|
|
);
|
|
|
|
|
|
|
|
const res = await presets.resolveConfigPresets(config);
|
|
|
|
|
|
|
|
expect(res.labels).toEqual(['self-hosted resolved']);
|
|
|
|
expect(local.getPreset.mock.calls).toHaveLength(1);
|
|
|
|
expect(local.getPreset.mock.calls[0][0].baseConfig).not.toBeUndefined();
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
2017-08-18 04:10:19 +00:00
|
|
|
});
|
|
|
|
describe('replaceArgs', () => {
|
|
|
|
const argMappings = {
|
|
|
|
arg0: 'a',
|
|
|
|
arg1: 'b',
|
|
|
|
arg2: 'c',
|
|
|
|
};
|
2017-11-03 10:56:25 +00:00
|
|
|
it('replaces args in strings', () => {
|
2017-08-18 04:10:19 +00:00
|
|
|
const str = '{{arg2}} foo {{arg0}}{{arg1}}';
|
|
|
|
const res = presets.replaceArgs(str, argMappings);
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
2017-11-03 10:56:25 +00:00
|
|
|
it('replaces args twice in same string', () => {
|
2017-08-18 04:10:19 +00:00
|
|
|
const str = '{{arg2}}{{arg0}} foo {{arg0}}{{arg1}}';
|
|
|
|
const res = presets.replaceArgs(str, argMappings);
|
|
|
|
expect(res).toEqual('ca foo ab');
|
|
|
|
});
|
2017-11-03 10:56:25 +00:00
|
|
|
it('replaces objects', () => {
|
2017-08-18 04:10:19 +00:00
|
|
|
const obj = {
|
|
|
|
foo: 'ha {{arg0}}',
|
|
|
|
bar: {
|
|
|
|
baz: '{{arg1}} boo',
|
|
|
|
aaa: {
|
|
|
|
bbb: 'woo {{arg2}}',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const res = presets.replaceArgs(obj, argMappings);
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
2017-11-03 10:56:25 +00:00
|
|
|
it('replaces arrays', () => {
|
2017-08-18 04:10:19 +00:00
|
|
|
const obj = {
|
|
|
|
foo: [
|
|
|
|
'{{arg0}}',
|
|
|
|
{
|
|
|
|
bar: '{{arg1}}',
|
|
|
|
baz: 5,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const res = presets.replaceArgs(obj, argMappings);
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('parsePreset', () => {
|
|
|
|
// default namespace
|
2017-11-03 10:56:25 +00:00
|
|
|
it('returns default package name', () => {
|
2017-08-18 04:10:19 +00:00
|
|
|
expect(presets.parsePreset(':base')).toMatchSnapshot();
|
|
|
|
});
|
2018-07-31 04:48:56 +00:00
|
|
|
it('parses github', () => {
|
|
|
|
expect(presets.parsePreset('github>some/repo')).toMatchSnapshot();
|
|
|
|
});
|
2020-04-28 09:41:56 +00:00
|
|
|
it('parses github subfiles', () => {
|
|
|
|
expect(
|
|
|
|
presets.parsePreset('github>some/repo:somefile')
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('parses github subfiles with preset name', () => {
|
|
|
|
expect(
|
|
|
|
presets.parsePreset('github>some/repo:somefile/somepreset')
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('parses github subfiles with preset and sub-preset name', () => {
|
|
|
|
expect(
|
|
|
|
presets.parsePreset(
|
|
|
|
'github>some/repo:somefile/somepreset/somesubpreset'
|
|
|
|
)
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
2021-03-20 23:03:10 +00:00
|
|
|
it('parses github subdirectories', () => {
|
|
|
|
expect(
|
|
|
|
presets.parsePreset('github>some/repo//somepath/somesubpath/somefile')
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('parses github toplevel file using subdirectory syntax', () => {
|
|
|
|
expect(
|
|
|
|
presets.parsePreset('github>some/repo//somefile')
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
2018-12-21 18:28:26 +00:00
|
|
|
it('parses gitlab', () => {
|
|
|
|
expect(presets.parsePreset('gitlab>some/repo')).toMatchSnapshot();
|
|
|
|
});
|
2020-12-09 12:31:06 +00:00
|
|
|
it('parses gitea', () => {
|
|
|
|
expect(presets.parsePreset('gitea>some/repo')).toMatchSnapshot();
|
|
|
|
});
|
2020-04-14 05:05:30 +00:00
|
|
|
it('parses local', () => {
|
|
|
|
expect(presets.parsePreset('local>some/repo')).toMatchSnapshot();
|
|
|
|
});
|
2021-03-25 15:48:54 +00:00
|
|
|
it('parses local with subdirectory', () => {
|
|
|
|
expect(
|
|
|
|
presets.parsePreset('local>some-group/some-repo//some-dir/some-file')
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
2020-04-14 05:05:30 +00:00
|
|
|
it('parses no prefix as local', () => {
|
|
|
|
expect(presets.parsePreset('some/repo')).toMatchSnapshot();
|
|
|
|
});
|
2017-11-03 10:56:25 +00:00
|
|
|
it('returns default package name with params', () => {
|
2017-08-18 04:10:19 +00:00
|
|
|
expect(
|
|
|
|
presets.parsePreset(':group(packages/eslint, eslint)')
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
// scoped namespace
|
2017-11-03 10:56:25 +00:00
|
|
|
it('returns simple scope', () => {
|
2017-08-18 04:10:19 +00:00
|
|
|
expect(presets.parsePreset('@somescope')).toMatchSnapshot();
|
|
|
|
});
|
2017-11-03 10:56:25 +00:00
|
|
|
it('returns simple scope and params', () => {
|
2017-08-18 04:10:19 +00:00
|
|
|
expect(presets.parsePreset('@somescope(param1)')).toMatchSnapshot();
|
|
|
|
});
|
2017-11-03 10:56:25 +00:00
|
|
|
it('returns scope with packageName and default', () => {
|
2017-08-18 04:10:19 +00:00
|
|
|
expect(
|
|
|
|
presets.parsePreset('@somescope/somepackagename')
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
2017-11-03 10:56:25 +00:00
|
|
|
it('returns scope with packageName and params and default', () => {
|
2017-08-18 04:10:19 +00:00
|
|
|
expect(
|
|
|
|
presets.parsePreset(
|
|
|
|
'@somescope/somepackagename(param1, param2, param3)'
|
|
|
|
)
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
2017-11-03 10:56:25 +00:00
|
|
|
it('returns scope with presetName', () => {
|
2017-08-18 04:10:19 +00:00
|
|
|
expect(
|
|
|
|
presets.parsePreset('@somescope:somePresetName')
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
2017-11-03 10:56:25 +00:00
|
|
|
it('returns scope with presetName and params', () => {
|
2017-08-18 04:10:19 +00:00
|
|
|
expect(
|
|
|
|
presets.parsePreset('@somescope:somePresetName(param1)')
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
2017-11-03 10:56:25 +00:00
|
|
|
it('returns scope with packageName and presetName', () => {
|
2017-08-18 04:10:19 +00:00
|
|
|
expect(
|
|
|
|
presets.parsePreset('@somescope/somepackagename:somePresetName')
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
2017-11-03 10:56:25 +00:00
|
|
|
it('returns scope with packageName and presetName and params', () => {
|
2017-08-18 04:10:19 +00:00
|
|
|
expect(
|
|
|
|
presets.parsePreset(
|
|
|
|
'@somescope/somepackagename:somePresetName(param1, param2)'
|
|
|
|
)
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
// non-scoped namespace
|
2017-11-03 10:56:25 +00:00
|
|
|
it('returns non-scoped default', () => {
|
2017-08-18 04:10:19 +00:00
|
|
|
expect(presets.parsePreset('somepackage')).toMatchSnapshot();
|
|
|
|
});
|
2017-11-03 10:56:25 +00:00
|
|
|
it('returns non-scoped package name', () => {
|
2017-08-18 04:10:19 +00:00
|
|
|
expect(presets.parsePreset('somepackage:webapp')).toMatchSnapshot();
|
|
|
|
});
|
2017-11-03 10:56:25 +00:00
|
|
|
it('returns non-scoped package name full', () => {
|
2017-08-18 04:10:19 +00:00
|
|
|
expect(
|
|
|
|
presets.parsePreset('renovate-config-somepackage:webapp')
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
2017-11-03 10:56:25 +00:00
|
|
|
it('returns non-scoped package name with params', () => {
|
2017-08-18 04:10:19 +00:00
|
|
|
expect(
|
|
|
|
presets.parsePreset('somepackage:webapp(param1)')
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('getPreset', () => {
|
2021-04-19 14:42:29 +00:00
|
|
|
it('handles removed presets with a migration', async () => {
|
|
|
|
const res = await presets.getPreset(':masterIssue', {});
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('handles removed presets with no migration', async () => {
|
|
|
|
const res = await presets.getPreset('helpers:oddIsUnstable', {});
|
|
|
|
expect(res).toEqual({});
|
|
|
|
});
|
2017-08-18 04:10:19 +00:00
|
|
|
it('gets linters', async () => {
|
2020-04-14 05:05:30 +00:00
|
|
|
const res = await presets.getPreset('packages:linters', {});
|
2017-08-18 04:10:19 +00:00
|
|
|
expect(res).toMatchSnapshot();
|
2021-01-29 10:43:42 +00:00
|
|
|
expect(res.matchPackageNames).toHaveLength(1);
|
2020-09-12 11:34:11 +00:00
|
|
|
expect(res.extends).toHaveLength(4);
|
2017-08-18 04:10:19 +00:00
|
|
|
});
|
|
|
|
it('gets parameterised configs', async () => {
|
2020-04-14 05:05:30 +00:00
|
|
|
const res = await presets.getPreset(
|
|
|
|
':group(packages:eslint, eslint)',
|
|
|
|
{}
|
|
|
|
);
|
2017-08-18 04:10:19 +00:00
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('handles missing params', async () => {
|
2020-04-14 05:05:30 +00:00
|
|
|
const res = await presets.getPreset(':group()', {});
|
2017-08-18 04:10:19 +00:00
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('ignores irrelevant params', async () => {
|
2020-04-14 05:05:30 +00:00
|
|
|
const res = await presets.getPreset(':pinVersions(foo, bar)', {});
|
2017-08-18 04:10:19 +00:00
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('handles 404 packages', async () => {
|
2020-03-07 10:27:10 +00:00
|
|
|
let e: Error;
|
2017-12-18 08:39:52 +00:00
|
|
|
try {
|
2020-04-14 05:05:30 +00:00
|
|
|
await presets.getPreset('notfound:foo', {});
|
2017-12-18 08:39:52 +00:00
|
|
|
} catch (err) {
|
|
|
|
e = err;
|
|
|
|
}
|
|
|
|
expect(e).toBeDefined();
|
2021-04-01 13:50:17 +00:00
|
|
|
expect(e.location).toMatchSnapshot();
|
2017-12-18 08:39:52 +00:00
|
|
|
expect(e.validationError).toMatchSnapshot();
|
|
|
|
expect(e.validationMessage).toMatchSnapshot();
|
2017-08-18 04:10:19 +00:00
|
|
|
});
|
|
|
|
it('handles no config', async () => {
|
2020-03-07 10:27:10 +00:00
|
|
|
let e: Error;
|
2017-12-18 08:39:52 +00:00
|
|
|
try {
|
2020-04-14 05:05:30 +00:00
|
|
|
await presets.getPreset('noconfig:foo', {});
|
2017-12-18 08:39:52 +00:00
|
|
|
} catch (err) {
|
|
|
|
e = err;
|
|
|
|
}
|
|
|
|
expect(e).toBeDefined();
|
2021-04-01 13:50:17 +00:00
|
|
|
expect(e.location).toMatchSnapshot();
|
2017-12-18 08:39:52 +00:00
|
|
|
expect(e.validationError).toMatchSnapshot();
|
|
|
|
expect(e.validationMessage).toMatchSnapshot();
|
2017-08-18 04:10:19 +00:00
|
|
|
});
|
|
|
|
it('handles throw errors', async () => {
|
2020-03-07 10:27:10 +00:00
|
|
|
let e: Error;
|
2017-12-18 08:39:52 +00:00
|
|
|
try {
|
2020-04-14 05:05:30 +00:00
|
|
|
await presets.getPreset('throw:foo', {});
|
2017-12-18 08:39:52 +00:00
|
|
|
} catch (err) {
|
|
|
|
e = err;
|
|
|
|
}
|
|
|
|
expect(e).toBeDefined();
|
2021-04-01 13:50:17 +00:00
|
|
|
expect(e.location).toMatchSnapshot();
|
2017-12-18 08:39:52 +00:00
|
|
|
expect(e.validationError).toMatchSnapshot();
|
|
|
|
expect(e.validationMessage).toMatchSnapshot();
|
2017-08-18 04:10:19 +00:00
|
|
|
});
|
|
|
|
it('handles preset not found', async () => {
|
2020-03-07 10:27:10 +00:00
|
|
|
let e: Error;
|
2017-12-18 08:39:52 +00:00
|
|
|
try {
|
2020-04-14 05:05:30 +00:00
|
|
|
await presets.getPreset('wrongpreset:foo', {});
|
2017-12-18 08:39:52 +00:00
|
|
|
} catch (err) {
|
|
|
|
e = err;
|
|
|
|
}
|
|
|
|
expect(e).toBeDefined();
|
2021-04-01 13:50:17 +00:00
|
|
|
expect(e.location).toMatchSnapshot();
|
2017-12-18 08:39:52 +00:00
|
|
|
expect(e.validationError).toMatchSnapshot();
|
|
|
|
expect(e.validationMessage).toMatchSnapshot();
|
2017-08-18 04:10:19 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|