2020-03-05 20:57:24 +00:00
|
|
|
import { UpdateType } from '../config';
|
2020-01-17 09:14:20 +00:00
|
|
|
import {
|
|
|
|
LANGUAGE_DOCKER,
|
|
|
|
LANGUAGE_JAVASCRIPT,
|
|
|
|
LANGUAGE_NODE,
|
|
|
|
LANGUAGE_PYTHON,
|
2020-03-05 20:57:24 +00:00
|
|
|
} from '../constants/languages';
|
2020-01-16 15:22:34 +00:00
|
|
|
|
2020-03-05 20:57:24 +00:00
|
|
|
import * as datasourceDocker from '../datasource/docker';
|
|
|
|
import * as datasourceOrb from '../datasource/orb';
|
2020-05-01 16:03:48 +00:00
|
|
|
import { Config, applyPackageRules } from './package-rules';
|
2019-08-23 13:46:31 +00:00
|
|
|
|
|
|
|
type TestConfig = Config & { x?: number; y?: number };
|
2018-05-09 06:03:59 +00:00
|
|
|
|
|
|
|
describe('applyPackageRules()', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config1: TestConfig = {
|
2018-05-09 06:03:59 +00:00
|
|
|
foo: 'bar',
|
|
|
|
|
|
|
|
packageRules: [
|
|
|
|
{
|
|
|
|
packageNames: ['a', 'b'],
|
|
|
|
x: 2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
packagePatterns: ['a', 'b'],
|
|
|
|
excludePackageNames: ['aa'],
|
|
|
|
excludePackagePatterns: ['d'],
|
|
|
|
y: 2,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2019-05-24 13:01:07 +00:00
|
|
|
it('applies', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: Config = {
|
2019-05-24 13:01:07 +00:00
|
|
|
depName: 'a',
|
|
|
|
isBump: true,
|
|
|
|
currentValue: '1.0.0',
|
|
|
|
packageRules: [
|
|
|
|
{
|
|
|
|
packagePatterns: ['*'],
|
|
|
|
matchCurrentVersion: '<= 2.0.0',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
packageNames: ['b'],
|
|
|
|
matchCurrentVersion: '<= 2.0.0',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
excludePackagePatterns: ['*'],
|
|
|
|
packageNames: ['b'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
updateTypes: ['bump'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
excludePackageNames: ['a'],
|
|
|
|
packageNames: ['b'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
matchCurrentVersion: '<= 2.0.0',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
expect(applyPackageRules(config)).toMatchSnapshot();
|
|
|
|
});
|
2018-05-09 06:03:59 +00:00
|
|
|
it('applies both rules for a', () => {
|
|
|
|
const dep = {
|
|
|
|
depName: 'a',
|
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config1, ...dep });
|
|
|
|
expect(res.x).toBe(2);
|
|
|
|
expect(res.y).toBe(2);
|
|
|
|
});
|
|
|
|
it('applies both rules for b', () => {
|
|
|
|
const dep = {
|
|
|
|
depName: 'b',
|
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config1, ...dep });
|
|
|
|
expect(res.x).toBe(2);
|
|
|
|
expect(res.y).toBe(2);
|
|
|
|
});
|
|
|
|
it('applies the second rule', () => {
|
|
|
|
const dep = {
|
|
|
|
depName: 'abc',
|
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config1, ...dep });
|
|
|
|
expect(res.x).toBeUndefined();
|
|
|
|
expect(res.y).toBe(2);
|
|
|
|
});
|
|
|
|
it('applies the second second rule', () => {
|
|
|
|
const dep = {
|
|
|
|
depName: 'bc',
|
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config1, ...dep });
|
|
|
|
expect(res.x).toBeUndefined();
|
|
|
|
expect(res.y).toBe(2);
|
|
|
|
});
|
|
|
|
it('excludes package name', () => {
|
|
|
|
const dep = {
|
|
|
|
depName: 'aa',
|
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config1, ...dep });
|
|
|
|
expect(res.x).toBeUndefined();
|
|
|
|
expect(res.y).toBeUndefined();
|
|
|
|
});
|
|
|
|
it('excludes package pattern', () => {
|
|
|
|
const dep = {
|
|
|
|
depName: 'bcd',
|
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config1, ...dep });
|
|
|
|
expect(res.x).toBeUndefined();
|
|
|
|
expect(res.y).toBeUndefined();
|
|
|
|
});
|
|
|
|
it('matches anything if missing inclusive rules', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2018-05-09 06:03:59 +00:00
|
|
|
packageRules: [
|
|
|
|
{
|
|
|
|
excludePackageNames: ['foo'],
|
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const res1 = applyPackageRules({
|
|
|
|
...config,
|
|
|
|
depName: 'foo',
|
|
|
|
});
|
|
|
|
expect(res1.x).toBeUndefined();
|
|
|
|
const res2 = applyPackageRules({
|
|
|
|
...config,
|
|
|
|
depName: 'bar',
|
|
|
|
});
|
|
|
|
expect(res2.x).toBeDefined();
|
|
|
|
});
|
|
|
|
it('supports inclusive or', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2018-05-09 06:03:59 +00:00
|
|
|
packageRules: [
|
|
|
|
{
|
|
|
|
packageNames: ['neutrino'],
|
|
|
|
packagePatterns: ['^@neutrino\\/'],
|
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const res1 = applyPackageRules({ ...config, depName: 'neutrino' });
|
|
|
|
expect(res1.x).toBeDefined();
|
|
|
|
const res2 = applyPackageRules({
|
|
|
|
...config,
|
|
|
|
depName: '@neutrino/something',
|
|
|
|
});
|
|
|
|
expect(res2.x).toBeDefined();
|
|
|
|
});
|
2020-05-18 12:33:44 +00:00
|
|
|
it('filters requested depType', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2018-05-09 06:03:59 +00:00
|
|
|
packageRules: [
|
|
|
|
{
|
|
|
|
depTypeList: ['dependencies', 'peerDependencies'],
|
|
|
|
packageNames: ['a'],
|
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const dep = {
|
|
|
|
depType: 'dependencies',
|
|
|
|
depName: 'a',
|
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config, ...dep });
|
|
|
|
expect(res.x).toBe(1);
|
2018-07-04 07:30:29 +00:00
|
|
|
});
|
2020-05-18 12:33:44 +00:00
|
|
|
it('filters from list of requested depTypes', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2019-01-21 04:44:14 +00:00
|
|
|
packageRules: [
|
|
|
|
{
|
|
|
|
depTypeList: ['test'],
|
|
|
|
packageNames: ['a'],
|
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const dep = {
|
|
|
|
depTypes: ['build', 'test'],
|
|
|
|
depName: 'a',
|
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config, ...dep });
|
|
|
|
expect(res.x).toBe(1);
|
|
|
|
});
|
2018-12-11 11:37:13 +00:00
|
|
|
it('filters managers with matching manager', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2018-12-11 11:37:13 +00:00
|
|
|
packageRules: [
|
|
|
|
{
|
2020-02-04 09:37:24 +00:00
|
|
|
managers: ['npm', 'meteor'],
|
2018-12-11 11:37:13 +00:00
|
|
|
packageNames: ['node'],
|
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const dep = {
|
|
|
|
depType: 'dependencies',
|
2020-01-17 09:14:20 +00:00
|
|
|
language: LANGUAGE_JAVASCRIPT,
|
2020-02-04 09:37:24 +00:00
|
|
|
manager: 'meteor',
|
2018-12-11 11:37:13 +00:00
|
|
|
depName: 'node',
|
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config, ...dep });
|
|
|
|
expect(res.x).toBe(1);
|
|
|
|
});
|
|
|
|
it('filters managers with non-matching manager', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2018-12-11 11:37:13 +00:00
|
|
|
packageRules: [
|
|
|
|
{
|
2020-02-04 09:37:24 +00:00
|
|
|
managers: ['dockerfile', 'npm'],
|
2018-12-11 11:37:13 +00:00
|
|
|
packageNames: ['node'],
|
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const dep = {
|
|
|
|
depType: 'dependencies',
|
2020-01-17 09:14:20 +00:00
|
|
|
language: LANGUAGE_PYTHON,
|
2020-02-04 09:37:24 +00:00
|
|
|
manager: 'pipenv',
|
2018-12-11 11:55:12 +00:00
|
|
|
depName: 'node',
|
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config, ...dep });
|
|
|
|
expect(res.x).toBeUndefined();
|
|
|
|
});
|
|
|
|
it('filters languages with matching language', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2018-12-11 11:55:12 +00:00
|
|
|
packageRules: [
|
|
|
|
{
|
2020-01-17 09:14:20 +00:00
|
|
|
languages: [LANGUAGE_JAVASCRIPT, LANGUAGE_NODE],
|
2018-12-11 11:55:12 +00:00
|
|
|
packageNames: ['node'],
|
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const dep = {
|
|
|
|
depType: 'dependencies',
|
2020-01-17 09:14:20 +00:00
|
|
|
language: LANGUAGE_JAVASCRIPT,
|
2020-02-04 09:37:24 +00:00
|
|
|
manager: 'meteor',
|
2018-12-11 11:55:12 +00:00
|
|
|
depName: 'node',
|
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config, ...dep });
|
|
|
|
expect(res.x).toBe(1);
|
|
|
|
});
|
|
|
|
it('filters languages with non-matching language', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2018-12-11 11:55:12 +00:00
|
|
|
packageRules: [
|
|
|
|
{
|
2020-01-17 09:14:20 +00:00
|
|
|
languages: [LANGUAGE_DOCKER],
|
2018-12-11 11:55:12 +00:00
|
|
|
packageNames: ['node'],
|
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const dep = {
|
|
|
|
depType: 'dependencies',
|
2020-01-17 09:14:20 +00:00
|
|
|
language: LANGUAGE_PYTHON,
|
2020-02-04 09:37:24 +00:00
|
|
|
manager: 'pipenv',
|
2018-12-11 11:37:13 +00:00
|
|
|
depName: 'node',
|
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config, ...dep });
|
|
|
|
expect(res.x).toBeUndefined();
|
|
|
|
});
|
2019-03-12 06:27:49 +00:00
|
|
|
it('filters datasources with matching datasource', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2019-03-12 06:27:49 +00:00
|
|
|
packageRules: [
|
|
|
|
{
|
2020-03-01 07:01:12 +00:00
|
|
|
datasources: [datasourceOrb.id, datasourceDocker.id],
|
2019-03-12 06:27:49 +00:00
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const dep = {
|
|
|
|
depType: 'dependencies',
|
2020-03-01 07:01:12 +00:00
|
|
|
datasource: datasourceOrb.id,
|
2019-03-12 06:27:49 +00:00
|
|
|
baseBranch: 'master',
|
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config, ...dep });
|
|
|
|
expect(res.x).toBe(1);
|
|
|
|
});
|
2019-03-11 16:42:30 +00:00
|
|
|
it('filters branches with matching branch', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2019-03-11 16:42:30 +00:00
|
|
|
packageRules: [
|
|
|
|
{
|
|
|
|
baseBranchList: ['master', 'staging'],
|
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const dep = {
|
2019-03-12 06:27:49 +00:00
|
|
|
depType: 'dependencies',
|
2020-03-01 07:01:12 +00:00
|
|
|
datasource: datasourceOrb.id,
|
2019-03-11 16:42:30 +00:00
|
|
|
baseBranch: 'master',
|
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config, ...dep });
|
|
|
|
expect(res.x).toBe(1);
|
|
|
|
});
|
2019-03-12 06:27:49 +00:00
|
|
|
it('filters datasources with non-matching datasource', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2019-03-12 06:27:49 +00:00
|
|
|
packageRules: [
|
|
|
|
{
|
2020-03-01 07:01:12 +00:00
|
|
|
datasources: [datasourceOrb.id],
|
2019-03-12 06:27:49 +00:00
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const dep = {
|
|
|
|
depType: 'dependencies',
|
|
|
|
baseBranch: 'staging',
|
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config, ...dep });
|
|
|
|
expect(res.x).toBeUndefined();
|
|
|
|
});
|
2019-03-11 16:42:30 +00:00
|
|
|
it('filters branches with non-matching branch', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2019-03-11 16:42:30 +00:00
|
|
|
packageRules: [
|
|
|
|
{
|
|
|
|
baseBranchList: ['master'],
|
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const dep = {
|
2019-03-12 06:27:49 +00:00
|
|
|
depType: 'dependencies',
|
2019-03-11 16:42:30 +00:00
|
|
|
baseBranch: 'staging',
|
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config, ...dep });
|
|
|
|
expect(res.x).toBeUndefined();
|
|
|
|
});
|
2018-07-04 07:36:05 +00:00
|
|
|
it('filters updateType', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2018-07-04 07:30:29 +00:00
|
|
|
packageRules: [
|
|
|
|
{
|
|
|
|
updateTypes: ['minor', 'patch'],
|
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const dep = {
|
|
|
|
depType: 'dependencies',
|
|
|
|
depName: 'a',
|
2019-08-23 13:46:31 +00:00
|
|
|
updateType: 'patch' as UpdateType,
|
2018-07-04 07:30:29 +00:00
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config, ...dep });
|
|
|
|
expect(res.x).toBe(1);
|
2018-05-09 06:03:59 +00:00
|
|
|
});
|
2018-12-11 11:03:09 +00:00
|
|
|
it('matches sourceUrlPrefixes', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2018-12-11 11:03:09 +00:00
|
|
|
packageRules: [
|
|
|
|
{
|
|
|
|
sourceUrlPrefixes: [
|
|
|
|
'https://github.com/foo/bar',
|
|
|
|
'https://github.com/renovatebot/',
|
|
|
|
],
|
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const dep = {
|
|
|
|
depType: 'dependencies',
|
|
|
|
depName: 'a',
|
2019-08-23 13:46:31 +00:00
|
|
|
updateType: 'patch' as UpdateType,
|
2018-12-11 11:03:09 +00:00
|
|
|
sourceUrl: 'https://github.com/renovatebot/presets',
|
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config, ...dep });
|
|
|
|
expect(res.x).toBe(1);
|
|
|
|
});
|
|
|
|
it('non-matches sourceUrlPrefixes', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2018-12-11 11:03:09 +00:00
|
|
|
packageRules: [
|
|
|
|
{
|
|
|
|
sourceUrlPrefixes: [
|
|
|
|
'https://github.com/foo/bar',
|
|
|
|
'https://github.com/renovatebot/',
|
|
|
|
],
|
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const dep = {
|
|
|
|
depType: 'dependencies',
|
|
|
|
depName: 'a',
|
2019-08-23 13:46:31 +00:00
|
|
|
updateType: 'patch' as UpdateType,
|
2018-12-11 11:03:09 +00:00
|
|
|
sourceUrl: 'https://github.com/vuejs/vue',
|
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config, ...dep });
|
|
|
|
expect(res.x).toBeUndefined();
|
|
|
|
});
|
|
|
|
it('handles sourceUrlPrefixes when missing sourceUrl', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2018-12-11 11:03:09 +00:00
|
|
|
packageRules: [
|
|
|
|
{
|
|
|
|
sourceUrlPrefixes: [
|
|
|
|
'https://github.com/foo/bar',
|
|
|
|
'https://github.com/renovatebot/',
|
|
|
|
],
|
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const dep = {
|
|
|
|
depType: 'dependencies',
|
|
|
|
depName: 'a',
|
2019-08-23 13:46:31 +00:00
|
|
|
updateType: 'patch' as UpdateType,
|
2018-12-11 11:03:09 +00:00
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config, ...dep });
|
|
|
|
expect(res.x).toBeUndefined();
|
|
|
|
});
|
2018-05-09 06:03:59 +00:00
|
|
|
it('filters naked depType', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2018-05-09 06:03:59 +00:00
|
|
|
packageRules: [
|
|
|
|
{
|
|
|
|
depTypeList: ['dependencies', 'peerDependencies'],
|
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const dep = {
|
|
|
|
depType: 'dependencies',
|
|
|
|
depName: 'a',
|
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config, ...dep });
|
|
|
|
expect(res.x).toBe(1);
|
|
|
|
});
|
2020-05-18 12:33:44 +00:00
|
|
|
it('filters out unrequested depType', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2018-05-09 06:03:59 +00:00
|
|
|
packageRules: [
|
|
|
|
{
|
|
|
|
depTypeList: ['dependencies', 'peerDependencies'],
|
|
|
|
packageNames: ['a'],
|
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const dep = {
|
|
|
|
depType: 'devDependencies',
|
|
|
|
depName: 'a',
|
|
|
|
};
|
|
|
|
const res = applyPackageRules({ ...config, ...dep });
|
|
|
|
expect(res.x).toBeUndefined();
|
|
|
|
});
|
|
|
|
it('checks if matchCurrentVersion selector is valid and satisfies the condition on range overlap', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2018-05-09 06:03:59 +00:00
|
|
|
packageRules: [
|
|
|
|
{
|
|
|
|
packageNames: ['test'],
|
|
|
|
matchCurrentVersion: '<= 2.0.0',
|
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const res1 = applyPackageRules({
|
|
|
|
...config,
|
|
|
|
...{
|
|
|
|
depName: 'test',
|
2018-06-04 03:48:20 +00:00
|
|
|
currentValue: '^1.0.0',
|
2018-06-03 15:13:46 +00:00
|
|
|
fromVersion: '1.0.3',
|
2018-05-09 06:03:59 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(res1.x).toBeDefined();
|
2018-06-03 15:13:46 +00:00
|
|
|
const res2 = applyPackageRules({
|
|
|
|
...config,
|
|
|
|
...{
|
|
|
|
depName: 'test',
|
2018-06-04 03:48:20 +00:00
|
|
|
currentValue: '^1.0.0',
|
2018-06-03 15:13:46 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(res2.x).toBeUndefined();
|
2018-05-09 06:03:59 +00:00
|
|
|
});
|
|
|
|
it('checks if matchCurrentVersion selector is valid and satisfies the condition on pinned to range overlap', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2018-05-09 06:03:59 +00:00
|
|
|
packageRules: [
|
|
|
|
{
|
|
|
|
packageNames: ['test'],
|
|
|
|
matchCurrentVersion: '>= 2.0.0',
|
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const res1 = applyPackageRules({
|
|
|
|
...config,
|
|
|
|
...{
|
|
|
|
depName: 'test',
|
2018-06-04 03:48:20 +00:00
|
|
|
currentValue: '2.4.6',
|
2018-06-03 15:13:46 +00:00
|
|
|
fromVersion: '2.4.6',
|
2018-05-09 06:03:59 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(res1.x).toBeDefined();
|
|
|
|
});
|
2019-11-29 12:59:25 +00:00
|
|
|
it('checks if matchCurrentVersion selector is a version and matches if currentValue is a range', () => {
|
|
|
|
const config: TestConfig = {
|
|
|
|
packageRules: [
|
|
|
|
{
|
|
|
|
packageNames: ['test'],
|
|
|
|
matchCurrentVersion: '2.1.0',
|
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const res1 = applyPackageRules({
|
|
|
|
...config,
|
|
|
|
...{
|
|
|
|
depName: 'test',
|
|
|
|
currentValue: '^2.0.0',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(res1.x).toBeDefined();
|
|
|
|
const res2 = applyPackageRules({
|
|
|
|
...config,
|
|
|
|
...{
|
|
|
|
depName: 'test',
|
|
|
|
currentValue: '~2.0.0',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(res2.x).toBeUndefined();
|
|
|
|
});
|
2018-05-09 06:03:59 +00:00
|
|
|
it('checks if matchCurrentVersion selector works with static values', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2018-05-09 06:03:59 +00:00
|
|
|
packageRules: [
|
|
|
|
{
|
|
|
|
packageNames: ['test'],
|
|
|
|
matchCurrentVersion: '4.6.0',
|
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const res1 = applyPackageRules({
|
|
|
|
...config,
|
|
|
|
...{
|
|
|
|
depName: 'test',
|
2018-06-04 03:48:20 +00:00
|
|
|
currentValue: '4.6.0',
|
2018-06-03 15:13:46 +00:00
|
|
|
fromVersion: '4.6.0',
|
2018-05-09 06:03:59 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(res1.x).toBeDefined();
|
|
|
|
});
|
|
|
|
it('matches paths', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const config: TestConfig = {
|
2018-05-09 06:03:59 +00:00
|
|
|
packageFile: 'examples/foo/package.json',
|
|
|
|
packageRules: [
|
|
|
|
{
|
|
|
|
paths: ['examples/**', 'lib/'],
|
|
|
|
x: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const res1 = applyPackageRules({
|
|
|
|
...config,
|
|
|
|
depName: 'test',
|
|
|
|
});
|
|
|
|
expect(res1.x).toBeDefined();
|
|
|
|
config.packageFile = 'package.json';
|
|
|
|
const res2 = applyPackageRules({
|
|
|
|
...config,
|
|
|
|
depName: 'test',
|
|
|
|
});
|
|
|
|
expect(res2.x).toBeUndefined();
|
|
|
|
config.packageFile = 'lib/a/package.json';
|
|
|
|
const res3 = applyPackageRules({
|
|
|
|
...config,
|
|
|
|
depName: 'test',
|
|
|
|
});
|
|
|
|
expect(res3.x).toBeDefined();
|
|
|
|
});
|
2019-05-24 13:01:07 +00:00
|
|
|
it('empty rules', () => {
|
|
|
|
expect(
|
|
|
|
applyPackageRules({ ...config1, packageRules: null })
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
2018-05-09 06:03:59 +00:00
|
|
|
});
|