Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(nuget): Refactor versioning tests (#11903)
- Loading branch information
Showing
2 changed files
with
61 additions
and
103 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |