renovate/test/versioning/semver.spec.ts

54 lines
1.7 KiB
TypeScript
Raw Normal View History

import semver from '../../lib/versioning/semver';
2018-04-10 03:20:46 +00:00
2018-06-03 15:00:58 +00:00
describe('semver.isValid(input)', () => {
it('should return null for irregular versions', () => {
expect(semver.isValid('17.04.0')).toBeFalsy();
});
2018-04-10 03:20:46 +00:00
it('should support simple semver', () => {
expect(semver.isValid('1.2.3')).toBeTruthy();
2018-04-10 03:20:46 +00:00
});
it('should support semver with dash', () => {
expect(semver.isValid('1.2.3-foo')).toBeTruthy();
2018-04-10 03:20:46 +00:00
});
it('should reject semver without dash', () => {
expect(semver.isValid('1.2.3foo')).toBeFalsy();
2018-04-10 03:20:46 +00:00
});
it('should reject ranges', () => {
expect(semver.isValid('~1.2.3')).toBeFalsy();
expect(semver.isValid('^1.2.3')).toBeFalsy();
expect(semver.isValid('>1.2.3')).toBeFalsy();
2018-04-10 03:20:46 +00:00
});
it('should reject github repositories', () => {
expect(semver.isValid('renovatebot/renovate')).toBeFalsy();
expect(semver.isValid('renovatebot/renovate#master')).toBeFalsy();
2018-04-10 03:20:46 +00:00
expect(
semver.isValid('https://github.com/renovatebot/renovate.git')
).toBeFalsy();
2018-04-10 03:20:46 +00:00
});
});
2018-06-05 12:52:40 +00:00
describe('semver.isSingleVersion()', () => {
it('returns true if naked version', () => {
expect(semver.isSingleVersion('1.2.3')).toBeTruthy();
expect(semver.isSingleVersion('1.2.3-alpha.1')).toBeTruthy();
2018-06-05 12:52:40 +00:00
});
it('returns false if equals', () => {
expect(semver.isSingleVersion('=1.2.3')).toBeFalsy();
expect(semver.isSingleVersion('= 1.2.3')).toBeFalsy();
2018-06-05 12:52:40 +00:00
});
it('returns false when not version', () => {
expect(semver.isSingleVersion('1.x')).toBeFalsy();
2018-06-05 12:52:40 +00:00
});
});
describe('semver.getNewValue()', () => {
it('uses toVersion', () => {
expect(
semver.getNewValue({
currentValue: '=1.0.0',
rangeStrategy: 'bump',
fromVersion: '1.0.0',
toVersion: '1.1.0',
})
).toEqual('1.1.0');
});
});