Skip to content
Snippets Groups Projects
Unverified Commit 3ca6855d authored by Sergei Zharinov's avatar Sergei Zharinov Committed by GitHub
Browse files

test(nuget): Refactor versioning tests (#11903)

parent b7e022e0
No related branches found
No related tags found
No related merge requests found
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`versioning/nuget/index isStable 1.0.0+c30d7625 1`] = `true`;
exports[`versioning/nuget/index isStable 1.2019.3.22 1`] = `true`;
exports[`versioning/nuget/index isStable 2.0.2-pre20191018090318 1`] = `false`;
exports[`versioning/nuget/index isStable 2.3.4-beta+1990ef74 1`] = `false`;
exports[`versioning/nuget/index isStable 3.0.0-beta 1`] = `false`;
exports[`versioning/nuget/index isStable 9.0.3 1`] = `true`;
exports[`versioning/nuget/index isVersion and isValid 1.0.0+c30d7625 1`] = `"1.0.0+c30d7625"`;
exports[`versioning/nuget/index isVersion and isValid 1.0.0+c30d7625 2`] = `"1.0.0+c30d7625"`;
exports[`versioning/nuget/index isVersion and isValid 1.2019.3.22 1`] = `"1.2019.3.22"`;
exports[`versioning/nuget/index isVersion and isValid 1.2019.3.22 2`] = `"1.2019.3.22"`;
exports[`versioning/nuget/index isVersion and isValid 2.0.2-pre20191018090318 1`] = `"2.0.2-pre20191018090318"`;
exports[`versioning/nuget/index isVersion and isValid 2.0.2-pre20191018090318 2`] = `"2.0.2-pre20191018090318"`;
exports[`versioning/nuget/index isVersion and isValid 2.3.4-beta+1990ef74 1`] = `"2.3.4-beta+1990ef74"`;
exports[`versioning/nuget/index isVersion and isValid 2.3.4-beta+1990ef74 2`] = `"2.3.4-beta+1990ef74"`;
exports[`versioning/nuget/index isVersion and isValid 3.0.0.beta 1`] = `null`;
exports[`versioning/nuget/index isVersion and isValid 3.0.0.beta 2`] = `null`;
exports[`versioning/nuget/index isVersion and isValid 3.0.0-beta 1`] = `"3.0.0-beta"`;
exports[`versioning/nuget/index isVersion and isValid 3.0.0-beta 2`] = `"3.0.0-beta"`;
exports[`versioning/nuget/index isVersion and isValid 5.1.2-+ 1`] = `null`;
exports[`versioning/nuget/index isVersion and isValid 5.1.2-+ 2`] = `null`;
exports[`versioning/nuget/index isVersion and isValid 9.0.3 1`] = `"9.0.3"`;
exports[`versioning/nuget/index isVersion and isValid 9.0.3 2`] = `"9.0.3"`;
exports[`versioning/nuget/index isVersion and isValid 17.04 1`] = `"17.04"`;
exports[`versioning/nuget/index isVersion and isValid 17.04 2`] = `"17.04"`;
import nuget from '.'; import nuget from '.';
describe('versioning/nuget/index', () => { describe('versioning/nuget/index', () => {
describe('isVersion and isValid', () => { test.each`
[ input | expected
'9.0.3', ${'9.0.3'} | ${true}
'1.2019.3.22', ${'1.2019.3.22'} | ${true}
'3.0.0-beta', ${'3.0.0-beta'} | ${true}
'2.0.2-pre20191018090318', ${'2.0.2-pre20191018090318'} | ${true}
'1.0.0+c30d7625', ${'1.0.0+c30d7625'} | ${true}
'2.3.4-beta+1990ef74', ${'2.3.4-beta+1990ef74'} | ${true}
'17.04', ${'17.04'} | ${true}
'3.0.0.beta', ${'3.0.0.beta'} | ${false}
'5.1.2-+', ${'5.1.2-+'} | ${false}
].forEach((version) => { `('isValid("$input") === $expected', ({ input, expected }) => {
it(version, () => { const res = !!nuget.isValid(input);
// FIXME: explicit assert condition expect(res).toBe(expected);
expect(nuget.isVersion(version)).toMatchSnapshot();
expect(nuget.isValid(version)).toMatchSnapshot();
});
});
});
describe('isStable', () => {
[
'9.0.3',
'1.2019.3.22',
'3.0.0-beta',
'2.0.2-pre20191018090318',
'1.0.0+c30d7625',
'2.3.4-beta+1990ef74',
].forEach((version) => {
it(version, () => {
// FIXME: explicit assert condition
expect(nuget.isStable(version)).toMatchSnapshot();
});
});
});
describe('isEqual', () => {
it('should ignore leading zeros', () => {
expect(nuget.equals('17.4', '17.04')).toBe(true);
});
it('should treat missing trailing version parts as zero', () => {
expect(nuget.equals('1.4', '1.4.0')).toBe(true);
expect(nuget.equals('1.0.110', '1.0.110.0')).toBe(true);
});
it('should ignore hash suffixes', () => {
expect(nuget.equals('1.0.0', '1.0.0+c30d7625')).toBe(true);
}); });
test.each`
input | expected
${'9.0.3'} | ${true}
${'1.2019.3.22'} | ${true}
${'3.0.0-beta'} | ${true}
${'2.0.2-pre20191018090318'} | ${true}
${'1.0.0+c30d7625'} | ${true}
${'2.3.4-beta+1990ef74'} | ${true}
${'17.04'} | ${true}
${'3.0.0.beta'} | ${false}
${'5.1.2-+'} | ${false}
`('isVersion("$input") === $expected', ({ input, expected }) => {
const res = !!nuget.isVersion(input);
expect(res).toBe(expected);
}); });
describe('isGreaterThan', () => {
it('should compare using release number then suffix', () => { test.each`
expect(nuget.isGreaterThan('2.4.2', '2.4.1')).toBe(true); input | expected
expect(nuget.isGreaterThan('2.4-beta', '2.4-alpha')).toBe(true); ${'9.0.3'} | ${true}
expect(nuget.isGreaterThan('1.9', '2')).toBe(false); ${'1.2019.3.22'} | ${true}
expect(nuget.isGreaterThan('1.9', '1.9.1')).toBe(false); ${'3.0.0-beta'} | ${false}
${'2.0.2-pre20191018090318'} | ${false}
${'1.0.0+c30d7625'} | ${true}
${'2.3.4-beta+1990ef74'} | ${false}
`('isStable("$input") === $expected', ({ input, expected }) => {
expect(nuget.isStable(input)).toBe(expected);
}); });
it('should prioritize non-prerelease over prerelease', () => {
expect(nuget.isGreaterThan('2.4.0', '2.4.0-beta')).toBe(true); test.each`
expect(nuget.isGreaterThan('2.4.0-alpha', '2.4.0')).toBe(false); a | b | expected
${'17.4'} | ${'17.04'} | ${true}
${'1.4'} | ${'1.4.0'} | ${true}
${'1.0.110'} | ${'1.0.110.0'} | ${true}
${'1.0.0'} | ${'1.0.0+c30d7625'} | ${true}
`('equals($a, $b) === $expected', ({ a, b, expected }) => {
expect(nuget.equals(a, b)).toBe(expected);
}); });
test.each`
a | b | expected
${'2.4.2'} | ${'2.4.1'} | ${true}
${'2.4-beta'} | ${'2.4-alpha'} | ${true}
${'1.9'} | ${'2'} | ${false}
${'1.9'} | ${'1.9.1'} | ${false}
${'2.4.0'} | ${'2.4.0-beta'} | ${true}
${'2.4.0-alpha'} | ${'2.4.0'} | ${false}
`('isGreaterThan($a, $b) === $expected', ({ a, b, expected }) => {
expect(nuget.isGreaterThan(a, b)).toBe(expected);
}); });
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment