Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Refactor loose versioning tests (#11807)
- Loading branch information
Showing
2 changed files
with
43 additions
and
61 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,61 +1,50 @@ | ||
import loose from '.'; | ||
|
||
describe('versioning/loose/index', () => { | ||
describe('isVersion', () => { | ||
['1.1', '1.3.RC2', '2.1-rc2'].forEach((version) => { | ||
it(version, () => { | ||
// FIXME: explicit assert condition | ||
expect(loose.isVersion(version)).toMatchSnapshot(); | ||
}); | ||
}); | ||
test.each` | ||
version | expected | ||
${'1.1'} | ${true} | ||
${'1.3.RC2'} | ${true} | ||
${'2.1-rc2'} | ${true} | ||
`('isVersion("$version") === $expected', ({ version, expected }) => { | ||
expect(!!loose.isVersion(version)).toBe(expected); | ||
}); | ||
describe('isValid(version)', () => { | ||
it('must support varied precision, from 1 to 6 sections', () => { | ||
[ | ||
'v1.4', | ||
'3.5.0', | ||
'4.2.21.Final', | ||
'0.6.5.1', | ||
'20100527', | ||
'2.1.0-M3', | ||
'4.3.20.RELEASE', | ||
'1.1-groovy-2.4', | ||
'0.8a', | ||
'3.1.0.GA', | ||
'3.0.0-beta.3', | ||
].forEach((version) => { | ||
expect(loose.isValid(version)).toBe(version); | ||
}); | ||
['foo', '1.2.3.4.5.6.7'].forEach((version) => { | ||
expect(loose.isValid(version)).toBeNull(); | ||
}); | ||
}); | ||
it('should return null if the version string looks like a git commit hash', () => { | ||
[ | ||
'0a1b2c3', | ||
'0a1b2c3d', | ||
'0a1b2c3d4e5f6a7b8c9d0a1b2c3d4e5f6a7b8c9d', | ||
].forEach((version) => { | ||
expect(loose.isValid(version)).toBeNull(); | ||
}); | ||
[ | ||
'0a1b2c3d4e5f6a7b8c9d0a1b2c3d4e5f6a7b8c9d0', | ||
'0a1b2C3', | ||
'0z1b2c3', | ||
'0A1b2c3d4e5f6a7b8c9d0a1b2c3d4e5f6a7b8c9d', | ||
'123098140293', | ||
].forEach((version) => { | ||
expect(loose.isValid(version)).toBe(version); | ||
}); | ||
}); | ||
|
||
test.each` | ||
version | expected | ||
${'v1.4'} | ${true} | ||
${'3.5.0'} | ${true} | ||
${'4.2.21.Final'} | ${true} | ||
${'0.6.5.1'} | ${true} | ||
${'20100527'} | ${true} | ||
${'2.1.0-M3'} | ${true} | ||
${'4.3.20.RELEASE'} | ${true} | ||
${'1.1-groovy-2.4'} | ${true} | ||
${'0.8a'} | ${true} | ||
${'3.1.0.GA'} | ${true} | ||
${'3.0.0-beta.3'} | ${true} | ||
${'foo'} | ${false} | ||
${'1.2.3.4.5.6.7'} | ${false} | ||
${'0a1b2c3'} | ${false} | ||
${'0a1b2c3d'} | ${false} | ||
${'0a1b2c3d4e5f6a7b8c9d0a1b2c3d4e5f6a7b8c9d'} | ${false} | ||
${'0a1b2c3d4e5f6a7b8c9d0a1b2c3d4e5f6a7b8c9d0'} | ${true} | ||
${'0a1b2C3'} | ${true} | ||
${'0z1b2c3'} | ${true} | ||
${'0A1b2c3d4e5f6a7b8c9d0a1b2c3d4e5f6a7b8c9d'} | ${true} | ||
${'123098140293'} | ${true} | ||
`('isValid("$version") === $expected', ({ version, expected }) => { | ||
expect(!!loose.isValid(version)).toBe(expected); | ||
}); | ||
describe('isGreaterThan(version)', () => { | ||
it('should compare using release number than suffix', () => { | ||
expect(loose.isGreaterThan('2.4.0', '2.4')).toBe(true); | ||
expect(loose.isGreaterThan('2.4.2', '2.4.1')).toBe(true); | ||
expect(loose.isGreaterThan('2.4.beta', '2.4.alpha')).toBe(true); | ||
expect(loose.isGreaterThan('1.9', '2')).toBe(false); | ||
expect(loose.isGreaterThan('1.9', '1.9.1')).toBe(false); | ||
}); | ||
|
||
test.each` | ||
a | b | expected | ||
${'2.4.0'} | ${'2.4'} | ${true} | ||
${'2.4.2'} | ${'2.4.1'} | ${true} | ||
${'2.4.beta'} | ${'2.4.alpha'} | ${true} | ||
${'1.9'} | ${'2'} | ${false} | ||
${'1.9'} | ${'1.9.1'} | ${false} | ||
`('isGreaterThan("$a", "$b") === $expected', ({ a, b, expected }) => { | ||
expect(loose.isGreaterThan(a, b)).toBe(expected); | ||
}); | ||
}); |