test(poetry): Refactor versioning tests (#11931)

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
This commit is contained in:
Sergei Zharinov 2021-09-28 17:24:51 +03:00 committed by GitHub
parent 63423a1729
commit b1f96481c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,608 +2,210 @@ import { api as versioning } from '.';
describe('versioning/poetry/index', () => { describe('versioning/poetry/index', () => {
describe('equals', () => { describe('equals', () => {
it.each([ test.each`
['1', '1'], a | b | expected
['1.0', '1'], ${'1'} | ${'1'} | ${true}
['1.0.0', '1'], ${'1.0'} | ${'1'} | ${true}
['1.9.0', '1.9'], ${'1.0.0'} | ${'1'} | ${true}
])('%s == %s', (a, b) => { ${'1.9.0'} | ${'1.9'} | ${true}
expect(versioning.equals(a, b)).toBe(true); ${'1'} | ${'2'} | ${false}
}); ${'1.9.1'} | ${'1.9'} | ${false}
${'1.9-beta'} | ${'1.9'} | ${false}
it.each([ `('equals("$a", "$b") === $expected', ({ a, b, expected }) => {
['1', '2'], expect(versioning.equals(a, b)).toBe(expected);
['1.9.1', '1.9'],
['1.9-beta', '1.9'],
])('%s != %s', (a, b) => {
expect(versioning.equals(a, b)).toBe(false);
}); });
}); });
describe('getMajor', () => { test.each`
it.each([ version | major | minor | patch
['1', 1], ${'1'} | ${1} | ${0} | ${0}
['1.9', 1], ${'1.9'} | ${1} | ${9} | ${0}
['1.9.0', 1], ${'1.9.0'} | ${1} | ${9} | ${0}
])('%s -> %i', (version, expected) => { ${'1.9.4'} | ${1} | ${9} | ${4}
expect(versioning.getMajor(version)).toEqual(expected); `(
}); 'getMajor, getMinor, getPatch for "$version"',
({ version, major, minor, patch }) => {
expect(versioning.getMajor(version)).toBe(major);
expect(versioning.getMinor(version)).toBe(minor);
expect(versioning.getPatch(version)).toBe(patch);
}
);
test.each`
a | b | expected
${'2'} | ${'1'} | ${true}
${'2.0'} | ${'1'} | ${true}
${'2.0.0'} | ${'1'} | ${true}
${'1.10.0'} | ${'1.9'} | ${true}
${'1.9'} | ${'1.9-beta'} | ${true}
${'1'} | ${'1'} | ${false}
${'1.0'} | ${'1'} | ${false}
${'1.0.0'} | ${'1'} | ${false}
${'1.9.0'} | ${'1.9'} | ${false}
`('isGreaterThan("$a", "$b") === $expected', ({ a, b, expected }) => {
expect(versioning.isGreaterThan(a, b)).toBe(expected);
}); });
describe('getMinor', () => { test.each`
it.each([ version | expected
['1', 0], ${'1'} | ${true}
['1.9', 9], ${'1.9'} | ${true}
['1.9.0', 9], ${'1.9.0'} | ${true}
])('%s -> %i', (version, expected) => { ${'1.9.4'} | ${true}
expect(versioning.getMinor(version)).toEqual(expected); ${'1.9.4-beta'} | ${false}
}); `('isStable("$version") === $expected', ({ version, expected }) => {
const res = !!versioning.isStable(version);
expect(res).toBe(expected);
}); });
describe('getPatch', () => { test.each`
it.each([ version | expected
['1', 0], ${'17.04.0'} | ${false}
['1.9', 0], ${'1.2.3'} | ${true}
['1.9.0', 0], ${'1.2.3-foo'} | ${true}
['1.9.4', 4], ${'1.2.3foo'} | ${false}
])('%s -> %i', (version, expected) => { ${'*'} | ${true}
expect(versioning.getPatch(version)).toEqual(expected); ${'~1.2.3'} | ${true}
}); ${'^1.2.3'} | ${true}
${'>1.2.3'} | ${true}
${'renovatebot/renovate'} | ${false}
${'renovatebot/renovate#master'} | ${false}
${'https://github.com/renovatebot/renovate.git'} | ${false}
`('isValid("$version") === $expected', ({ version, expected }) => {
expect(!!versioning.isValid(version)).toBe(expected);
}); });
describe('isGreaterThan', () => { test.each`
it.each([ version | expected
['2', '1'], ${'1.2.3'} | ${true}
['2.0', '1'], ${'1.2.3-alpha.1'} | ${true}
['2.0.0', '1'], ${'=1.2.3'} | ${true}
['1.10.0', '1.9'], ${'= 1.2.3'} | ${true}
['1.9', '1.9-beta'], ${'1.*'} | ${false}
])('%s > %s', (a, b) => { `('isSingleVersion("$version") === $expected', ({ version, expected }) => {
expect(versioning.isGreaterThan(a, b)).toBe(true); expect(!!versioning.isSingleVersion(version)).toBe(expected);
});
it.each([
['1', '1'],
['1.0', '1'],
['1.0.0', '1'],
['1.9.0', '1.9'],
])('%s <= %s', (a, b) => {
expect(versioning.isGreaterThan(a, b)).toBe(false);
});
}); });
describe('isStable', () => { test.each`
it.each([ version | range | expected
['1', true], ${'4.2.0'} | ${'4.2, >= 3.0, < 5.0.0'} | ${true}
['1.9', true], ${'4.2.0'} | ${'2.0, >= 3.0, < 5.0.0'} | ${false}
['1.9.0', true], ${'4.2.2'} | ${'4.2.0, < 4.2.4'} | ${false}
['1.9.4', true], ${'4.2.2'} | ${'^4.2.0, < 4.2.4'} | ${true}
['1.9.4-beta', false], ${'4.2.0'} | ${'4.3.0, 3.0.0'} | ${false}
])('%s -> %i', (version, expected) => { ${'4.2.0'} | ${'> 5.0.0, <= 6.0.0'} | ${false}
expect(versioning.isStable(version)).toEqual(expected); ${'4.2.0'} | ${'*'} | ${true}
}); ${'1.4'} | ${'1.4'} | ${true}
}); `(
'matches("$version", "$range") === "$expected"',
({ version, range, expected }) => {
expect(versioning.matches(version, range)).toBe(expected);
}
);
describe('isValid(input)', () => { test.each`
it('should return null for irregular versions', () => { version | range | expected
expect(versioning.isValid('17.04.0')).toBeFalsy(); ${'0.9.0'} | ${'>= 1.0.0 <= 2.0.0'} | ${true}
}); ${'1.9.0'} | ${'>= 1.0.0 <= 2.0.0'} | ${false}
it('should support simple semver', () => { `(
expect(versioning.isValid('1.2.3')).toBeTruthy(); 'isLessThanRange("$version", "$range") === "$expected"',
}); ({ version, range, expected }) => {
it('should support semver with dash', () => { expect(versioning.isLessThanRange(version, range)).toBe(expected);
expect(versioning.isValid('1.2.3-foo')).toBeTruthy(); }
}); );
it('should reject semver without dash', () => {
expect(versioning.isValid('1.2.3foo')).toBeFalsy();
});
it('should work with wildcards', () => {
expect(versioning.isValid('*')).toBeTruthy();
});
it('should support ranges', () => {
expect(versioning.isValid('~1.2.3')).toBeTruthy();
expect(versioning.isValid('^1.2.3')).toBeTruthy();
expect(versioning.isValid('>1.2.3')).toBeTruthy();
});
it('should reject github repositories', () => {
expect(versioning.isValid('renovatebot/renovate')).toBeFalsy();
expect(versioning.isValid('renovatebot/renovate#master')).toBeFalsy();
expect(
versioning.isValid('https://github.com/renovatebot/renovate.git')
).toBeFalsy();
});
});
describe('isSingleVersion()', () => {
it('returns true if naked version', () => {
expect(versioning.isSingleVersion('1.2.3')).toBeTruthy();
expect(versioning.isSingleVersion('1.2.3-alpha.1')).toBeTruthy();
});
it('returns true if equals', () => {
expect(versioning.isSingleVersion('=1.2.3')).toBeTruthy();
expect(versioning.isSingleVersion('= 1.2.3')).toBeTruthy();
});
it('returns false when not version', () => {
expect(versioning.isSingleVersion('1.*')).toBeFalsy();
});
});
describe('matches()', () => {
it('handles comma', () => {
expect(versioning.matches('4.2.0', '4.2, >= 3.0, < 5.0.0')).toBe(true);
expect(versioning.matches('4.2.0', '2.0, >= 3.0, < 5.0.0')).toBe(false);
expect(versioning.matches('4.2.2', '4.2.0, < 4.2.4')).toBe(false);
expect(versioning.matches('4.2.2', '^4.2.0, < 4.2.4')).toBe(true);
expect(versioning.matches('4.2.0', '4.3.0, 3.0.0')).toBe(false);
expect(versioning.matches('4.2.0', '> 5.0.0, <= 6.0.0')).toBe(false);
});
it('handles wildcards', () => {
expect(versioning.matches('4.2.0', '*')).toBe(true);
});
it('handles short', () => {
expect(versioning.matches('1.4', '1.4')).toBe(true);
});
});
describe('isLessThanRange()', () => {
it('handles comma', () => {
expect(versioning.isLessThanRange('0.9.0', '>= 1.0.0 <= 2.0.0')).toBe(
true
);
expect(versioning.isLessThanRange('1.9.0', '>= 1.0.0 <= 2.0.0')).toBe(
false
);
});
});
describe('minSatisfyingVersion()', () => {
it('handles comma', () => {
expect(
versioning.minSatisfyingVersion(
['0.4.0', '0.5.0', '4.2.0', '4.3.0', '5.0.0'],
'4.*, > 4.2'
)
).toBe('4.3.0');
expect(
versioning.minSatisfyingVersion(
['0.4.0', '0.5.0', '4.2.0', '5.0.0'],
'^4.0.0'
)
).toBe('4.2.0');
expect(
versioning.minSatisfyingVersion(
['0.4.0', '0.5.0', '4.2.0', '5.0.0'],
'^4.0.0, = 0.5.0'
)
).toBeNull();
expect(
versioning.minSatisfyingVersion(
['0.4.0', '0.5.0', '4.2.0', '5.0.0'],
'^4.0.0, > 4.1.0, <= 4.3.5'
)
).toBe('4.2.0');
expect(
versioning.minSatisfyingVersion(
['0.4.0', '0.5.0', '4.2.0', '5.0.0'],
'^6.2.0, 3.*'
)
).toBeNull();
});
});
describe('getSatisfyingVersion()', () => {
it('handles comma', () => {
expect(
versioning.getSatisfyingVersion(
['4.2.1', '0.4.0', '0.5.0', '4.0.0', '4.2.0', '5.0.0'],
'4.*.0, < 4.2.5'
)
).toBe('4.2.1');
expect(
versioning.getSatisfyingVersion(
['0.4.0', '0.5.0', '4.0.0', '4.2.0', '5.0.0', '5.0.3'],
'5.0, > 5.0.0'
)
).toBe('5.0.3');
});
});
describe('getNewValue()', () => { test.each`
it('bumps exact', () => { versions | range | expected
expect( ${['0.4.0', '0.5.0', '4.2.0', '4.3.0', '5.0.0']} | ${'4.*, > 4.2'} | ${'4.3.0'}
versioning.getNewValue({ ${['0.4.0', '0.5.0', '4.2.0', '5.0.0']} | ${'^4.0.0'} | ${'4.2.0'}
currentValue: '1.0.0', ${['0.4.0', '0.5.0', '4.2.0', '5.0.0']} | ${'^4.0.0, = 0.5.0'} | ${null}
rangeStrategy: 'bump', ${['0.4.0', '0.5.0', '4.2.0', '5.0.0']} | ${'^4.0.0, > 4.1.0, <= 4.3.5'} | ${'4.2.0'}
currentVersion: '1.0.0', ${['0.4.0', '0.5.0', '4.2.0', '5.0.0']} | ${'^6.2.0, 3.*'} | ${null}
newVersion: '1.1.0', `(
}) 'minSatisfyingVersion($versions, "$range") === $expected',
).toEqual('1.1.0'); ({ versions, range, expected }) => {
expect( expect(versioning.minSatisfyingVersion(versions, range)).toBe(expected);
versioning.getNewValue({ }
currentValue: ' 1.0.0', );
rangeStrategy: 'bump',
currentVersion: '1.0.0',
newVersion: '1.1.0',
})
).toEqual('1.1.0');
expect(
versioning.getNewValue({
currentValue: '1.0.0',
rangeStrategy: 'bump',
currentVersion: '1.0.0',
newVersion: '1.1.0',
})
).toEqual('1.1.0');
});
it('bumps equals', () => {
expect(
versioning.getNewValue({
currentValue: '=1.0.0',
rangeStrategy: 'bump',
currentVersion: '1.0.0',
newVersion: '1.1.0',
})
).toEqual('=1.1.0');
expect(
versioning.getNewValue({
currentValue: '= 1.0.0',
rangeStrategy: 'bump',
currentVersion: '1.0.0',
newVersion: '1.1.0',
})
).toEqual('=1.1.0');
});
it('bumps equals space', () => {
expect(
versioning.getNewValue({
currentValue: '= 1.0.0',
rangeStrategy: 'bump',
currentVersion: '1.0.0',
newVersion: '1.1.0',
})
).toEqual('=1.1.0');
expect(
versioning.getNewValue({
currentValue: ' = 1.0.0',
rangeStrategy: 'bump',
currentVersion: '1.0.0',
newVersion: '1.1.0',
})
).toEqual('=1.1.0');
expect(
versioning.getNewValue({
currentValue: ' = 1.0.0',
rangeStrategy: 'bump',
currentVersion: '1.0.0',
newVersion: '1.1.0',
})
).toEqual('=1.1.0');
expect(
versioning.getNewValue({
currentValue: '= 1.0.0',
rangeStrategy: 'bump',
currentVersion: '1.0.0',
newVersion: '1.1.0',
})
).toEqual('=1.1.0');
});
it('bumps short caret to same', () => {
expect(
versioning.getNewValue({
currentValue: '^1.0',
rangeStrategy: 'bump',
currentVersion: '1.0.0',
newVersion: '1.0.7',
})
).toEqual('^1.0');
});
it('replaces caret with newer', () => {
expect(
versioning.getNewValue({
currentValue: '^1.0.0',
rangeStrategy: 'replace',
currentVersion: '1.0.0',
newVersion: '2.0.7',
})
).toEqual('^2.0.0');
});
it('handles precision change caret', () => {
expect(
versioning.getNewValue({
currentValue: '^5.0.3',
rangeStrategy: 'replace',
currentVersion: '5.3.1',
newVersion: '5.5',
})
).toEqual('^5.0.3');
});
it('replaces naked version', () => {
expect(
versioning.getNewValue({
currentValue: '1.0.0',
rangeStrategy: 'replace',
currentVersion: '1.0.0',
newVersion: '2.0.7',
})
).toEqual('2.0.7');
});
it('replaces with version range', () => {
expect(
versioning.getNewValue({
currentValue: '^1.0.0',
rangeStrategy: 'replace',
currentVersion: '1.0.0',
newVersion: '2.0.7',
})
).toEqual('^2.0.0');
});
it('returns currentValue', () => {
expect(
versioning.getNewValue({
currentValue: '^0.5.15',
rangeStrategy: 'replace',
currentVersion: '0.5.15',
newVersion: '0.6',
})
).toEqual('^0.5.15');
});
it('bumps naked caret', () => {
expect(
versioning.getNewValue({
currentValue: '^1',
rangeStrategy: 'bump',
currentVersion: '1.0.0',
newVersion: '2.1.7',
})
).toEqual('^2');
});
it('bumps naked tilde', () => {
expect(
versioning.getNewValue({
currentValue: '~1',
rangeStrategy: 'bump',
currentVersion: '1.0.0',
newVersion: '1.1.7',
})
).toEqual('~1');
});
it('bumps naked major', () => {
expect(
versioning.getNewValue({
currentValue: '5',
rangeStrategy: 'bump',
currentVersion: '5.0.0',
newVersion: '5.1.7',
})
).toEqual('5');
expect(
versioning.getNewValue({
currentValue: '5',
rangeStrategy: 'bump',
currentVersion: '5.0.0',
newVersion: '6.1.7',
})
).toEqual('6');
});
it('bumps naked minor', () => {
expect(
versioning.getNewValue({
currentValue: '5.0',
rangeStrategy: 'bump',
currentVersion: '5.0.0',
newVersion: '5.0.7',
})
).toEqual('5.0');
expect(
versioning.getNewValue({
currentValue: '5.0',
rangeStrategy: 'bump',
currentVersion: '5.0.0',
newVersion: '5.1.7',
})
).toEqual('5.1');
expect(
versioning.getNewValue({
currentValue: '5.0',
rangeStrategy: 'bump',
currentVersion: '5.0.0',
newVersion: '6.1.7',
})
).toEqual('6.1');
});
it('replaces minor', () => {
expect(
versioning.getNewValue({
currentValue: '5.0',
rangeStrategy: 'replace',
currentVersion: '5.0.0',
newVersion: '6.1.7',
})
).toEqual('6.1');
});
it('replaces equals', () => {
expect(
versioning.getNewValue({
currentValue: '=1.0.0',
rangeStrategy: 'replace',
currentVersion: '1.0.0',
newVersion: '1.1.0',
})
).toEqual('=1.1.0');
});
it('bumps caret to prerelease', () => {
expect(
versioning.getNewValue({
currentValue: '^1',
rangeStrategy: 'bump',
currentVersion: '1.0.0',
newVersion: '1.0.7-prerelease.1',
})
).toEqual('^1.0.7-prerelease.1');
});
it('replaces with newer', () => {
expect(
versioning.getNewValue({
currentValue: '^1.0.0',
rangeStrategy: 'replace',
currentVersion: '1.0.0',
newVersion: '1.2.3',
})
).toEqual('^1.0.0');
});
it('bumps short tilde', () => {
expect(
versioning.getNewValue({
currentValue: '~1.0',
rangeStrategy: 'bump',
currentVersion: '1.0.0',
newVersion: '1.1.7',
})
).toEqual('~1.1');
});
it('handles long asterisk', () => {
expect(
versioning.getNewValue({
currentValue: '1.0.*',
rangeStrategy: 'replace',
currentVersion: '1.0.0',
newVersion: '1.1.0',
})
).toEqual('1.1.*');
});
it('handles short asterisk', () => {
expect(
versioning.getNewValue({
currentValue: '1.*',
rangeStrategy: 'replace',
currentVersion: '1.0.0',
newVersion: '2.1.0',
})
).toEqual('2.*');
});
it('handles updating from stable to unstable', () => {
expect(
versioning.getNewValue({
currentValue: '~0.6.1',
rangeStrategy: 'replace',
currentVersion: '0.6.8',
newVersion: '0.7.0-rc.2',
})
).toEqual('~0.7.0-rc');
});
it('handles less than version requirements', () => {
expect(
versioning.getNewValue({
currentValue: '<1.3.4',
rangeStrategy: 'replace',
currentVersion: '1.2.3',
newVersion: '1.5.0',
})
).toEqual('<1.5.1');
expect(
versioning.getNewValue({
currentValue: '< 1.3.4',
rangeStrategy: 'replace',
currentVersion: '1.2.3',
newVersion: '1.5.0',
})
).toEqual('< 1.5.1');
expect(
versioning.getNewValue({
currentValue: '< 1.3.4',
rangeStrategy: 'replace',
currentVersion: '1.2.3',
newVersion: '1.5.0',
})
).toEqual('< 1.5.1');
});
it('handles less than equals version requirements', () => {
expect(
versioning.getNewValue({
currentValue: '<=1.3.4',
rangeStrategy: 'replace',
currentVersion: '1.2.3',
newVersion: '1.5.0',
})
).toEqual('<=1.5.0');
expect(
versioning.getNewValue({
currentValue: '<= 1.3.4',
rangeStrategy: 'replace',
currentVersion: '1.2.3',
newVersion: '1.5.0',
})
).toEqual('<= 1.5.0');
expect(
versioning.getNewValue({
currentValue: '<= 1.3.4',
rangeStrategy: 'replace',
currentVersion: '1.2.3',
newVersion: '1.5.0',
})
).toEqual('<= 1.5.0');
});
it('handles replacing short caret versions', () => {
expect(
versioning.getNewValue({
currentValue: '^1.2',
rangeStrategy: 'replace',
currentVersion: '1.2.3',
newVersion: '2.0.0',
})
).toEqual('^2.0');
expect(
versioning.getNewValue({
currentValue: '^1',
rangeStrategy: 'replace',
currentVersion: '1.2.3',
newVersion: '2.0.0',
})
).toEqual('^2');
});
it('handles replacing short tilde versions', () => {
expect(
versioning.getNewValue({
currentValue: '~1.2',
rangeStrategy: 'replace',
currentVersion: '1.2.3',
newVersion: '2.0.0',
})
).toEqual('~2.0');
expect(
versioning.getNewValue({
currentValue: '~1',
rangeStrategy: 'replace',
currentVersion: '1.2.3',
newVersion: '2.0.0',
})
).toEqual('~2');
});
it('widens range', () => {
expect(
versioning.getNewValue({
currentValue: '^2.2',
rangeStrategy: 'widen',
currentVersion: '2.2.0',
newVersion: '3.0.0',
})
).toEqual('^2.2 || ^3.0.0');
});
});
describe('sortVersions()', () => { test.each`
it.each([ versions | range | expected
['2', '1'], ${['4.2.1', '0.4.0', '0.5.0', '4.0.0', '4.2.0', '5.0.0']} | ${'4.*.0, < 4.2.5'} | ${'4.2.1'}
['2.0', '1'], ${['0.4.0', '0.5.0', '4.0.0', '4.2.0', '5.0.0', '5.0.3']} | ${'5.0, > 5.0.0'} | ${'5.0.3'}
['2.0.0', '1'], `(
['1.10.0', '1.9'], 'getSatisfyingVersion($versions, "$range") === $expected',
['1.9', '1.9-beta'], ({ versions, range, expected }) => {
])('%s > %s', (a, b) => { expect(versioning.getSatisfyingVersion(versions, range)).toBe(expected);
expect(versioning.sortVersions(a, b)).toBe(1); }
}); );
test.each`
currentValue | rangeStrategy | currentVersion | newVersion | expected
${'1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.0'} | ${'1.1.0'}
${' 1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.0'} | ${'1.1.0'}
${'1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.0'} | ${'1.1.0'}
${'=1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.0'} | ${'=1.1.0'}
${'= 1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.0'} | ${'=1.1.0'}
${'= 1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.0'} | ${'=1.1.0'}
${' = 1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.0'} | ${'=1.1.0'}
${' = 1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.0'} | ${'=1.1.0'}
${'= 1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.0'} | ${'=1.1.0'}
${'^1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.0.7'} | ${'^1.0'}
${'^1.0.0'} | ${'replace'} | ${'1.0.0'} | ${'2.0.7'} | ${'^2.0.0'}
${'^5.0.3'} | ${'replace'} | ${'5.3.1'} | ${'5.5'} | ${'^5.0.3'}
${'1.0.0'} | ${'replace'} | ${'1.0.0'} | ${'2.0.7'} | ${'2.0.7'}
${'^1.0.0'} | ${'replace'} | ${'1.0.0'} | ${'2.0.7'} | ${'^2.0.0'}
${'^0.5.15'} | ${'replace'} | ${'0.5.15'} | ${'0.6'} | ${'^0.5.15'}
${'^1'} | ${'bump'} | ${'1.0.0'} | ${'2.1.7'} | ${'^2'}
${'~1'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'~1'}
${'5'} | ${'bump'} | ${'5.0.0'} | ${'5.1.7'} | ${'5'}
${'5'} | ${'bump'} | ${'5.0.0'} | ${'6.1.7'} | ${'6'}
${'5.0'} | ${'bump'} | ${'5.0.0'} | ${'5.0.7'} | ${'5.0'}
${'5.0'} | ${'bump'} | ${'5.0.0'} | ${'5.1.7'} | ${'5.1'}
${'5.0'} | ${'bump'} | ${'5.0.0'} | ${'6.1.7'} | ${'6.1'}
${'5.0'} | ${'replace'} | ${'5.0.0'} | ${'6.1.7'} | ${'6.1'}
${'=1.0.0'} | ${'replace'} | ${'1.0.0'} | ${'1.1.0'} | ${'=1.1.0'}
${'^1'} | ${'bump'} | ${'1.0.0'} | ${'1.0.7-prerelease.1'} | ${'^1.0.7-prerelease.1'}
${'^1.0.0'} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'^1.0.0'}
${'~1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'~1.1'}
${'1.0.*'} | ${'replace'} | ${'1.0.0'} | ${'1.1.0'} | ${'1.1.*'}
${'1.*'} | ${'replace'} | ${'1.0.0'} | ${'2.1.0'} | ${'2.*'}
${'~0.6.1'} | ${'replace'} | ${'0.6.8'} | ${'0.7.0-rc.2'} | ${'~0.7.0-rc'}
${'<1.3.4'} | ${'replace'} | ${'1.2.3'} | ${'1.5.0'} | ${'<1.5.1'}
${'< 1.3.4'} | ${'replace'} | ${'1.2.3'} | ${'1.5.0'} | ${'< 1.5.1'}
${'< 1.3.4'} | ${'replace'} | ${'1.2.3'} | ${'1.5.0'} | ${'< 1.5.1'}
${'<=1.3.4'} | ${'replace'} | ${'1.2.3'} | ${'1.5.0'} | ${'<=1.5.0'}
${'<= 1.3.4'} | ${'replace'} | ${'1.2.3'} | ${'1.5.0'} | ${'<= 1.5.0'}
${'<= 1.3.4'} | ${'replace'} | ${'1.2.3'} | ${'1.5.0'} | ${'<= 1.5.0'}
${'^1.2'} | ${'replace'} | ${'1.2.3'} | ${'2.0.0'} | ${'^2.0'}
${'^1'} | ${'replace'} | ${'1.2.3'} | ${'2.0.0'} | ${'^2'}
${'~1.2'} | ${'replace'} | ${'1.2.3'} | ${'2.0.0'} | ${'~2.0'}
${'~1'} | ${'replace'} | ${'1.2.3'} | ${'2.0.0'} | ${'~2'}
${'^2.2'} | ${'widen'} | ${'2.2.0'} | ${'3.0.0'} | ${'^2.2 || ^3.0.0'}
`(
'getNewValue("$currentValue", "$rangeStrategy", "$currentVersion", "$newVersion") === "$expected"',
({ currentValue, rangeStrategy, currentVersion, newVersion, expected }) => {
const res = versioning.getNewValue({
currentValue,
rangeStrategy,
currentVersion,
newVersion,
});
expect(res).toEqual(expected);
}
);
it.each([ test.each`
['1', '1'], a | b | expected
['1.0', '1'], ${'2'} | ${'1'} | ${1}
['1.0.0', '1'], ${'2.0'} | ${'1'} | ${1}
['1.9.0', '1.9'], ${'2.0.0'} | ${'1'} | ${1}
])('%s == %s', (a, b) => { ${'1.10.0'} | ${'1.9'} | ${1}
expect(versioning.sortVersions(a, b)).toBe(0); ${'1.9'} | ${'1.9-beta'} | ${1}
}); ${'1'} | ${'1'} | ${0}
${'1.0'} | ${'1'} | ${0}
${'1.0.0'} | ${'1'} | ${0}
${'1.9.0'} | ${'1.9'} | ${0}
`('sortVersions("$a", "$b") === $expected', ({ a, b, expected }) => {
expect(versioning.sortVersions(a, b)).toEqual(expected);
}); });
}); });