Skip to content

Commit

Permalink
test(nuget): Refactor versioning tests (#11903)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Sep 27, 2021
1 parent b7e022e commit 3ca6855
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 103 deletions.
49 changes: 0 additions & 49 deletions lib/versioning/nuget/__snapshots__/index.spec.ts.snap

This file was deleted.

115 changes: 61 additions & 54 deletions lib/versioning/nuget/index.spec.ts
@@ -1,62 +1,69 @@
import nuget from '.';

describe('versioning/nuget/index', () => {
describe('isVersion and isValid', () => {
[
'9.0.3',
'1.2019.3.22',
'3.0.0-beta',
'2.0.2-pre20191018090318',
'1.0.0+c30d7625',
'2.3.4-beta+1990ef74',
'17.04',
'3.0.0.beta',
'5.1.2-+',
].forEach((version) => {
it(version, () => {
// FIXME: explicit assert condition
expect(nuget.isVersion(version)).toMatchSnapshot();
expect(nuget.isValid(version)).toMatchSnapshot();
});
});
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}
`('isValid("$input") === $expected', ({ input, expected }) => {
const res = !!nuget.isValid(input);
expect(res).toBe(expected);
});
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();
});
});

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('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'} | ${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);
});
describe('isGreaterThan', () => {
it('should compare using release number then suffix', () => {
expect(nuget.isGreaterThan('2.4.2', '2.4.1')).toBe(true);
expect(nuget.isGreaterThan('2.4-beta', '2.4-alpha')).toBe(true);
expect(nuget.isGreaterThan('1.9', '2')).toBe(false);
expect(nuget.isGreaterThan('1.9', '1.9.1')).toBe(false);
});
it('should prioritize non-prerelease over prerelease', () => {
expect(nuget.isGreaterThan('2.4.0', '2.4.0-beta')).toBe(true);
expect(nuget.isGreaterThan('2.4.0-alpha', '2.4.0')).toBe(false);
});

test.each`
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 comments on commit 3ca6855

Please sign in to comment.