Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Refactor loose versioning tests #11807

Merged
merged 1 commit into from Sep 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
});
});