Skip to content

Commit

Permalink
test: Refactor loose versioning tests (#11807)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Sep 19, 2021
1 parent 579c69a commit 55ea322
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 61 deletions.
7 changes: 0 additions & 7 deletions lib/versioning/loose/__snapshots__/index.spec.ts.snap

This file was deleted.

97 changes: 43 additions & 54 deletions lib/versioning/loose/index.spec.ts
@@ -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);
});
});

0 comments on commit 55ea322

Please sign in to comment.