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(utils): Add additional tests for version helper functions #562

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions src/utils/__tests__/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
expect(isValidVersion('1.2.3rc1')).toBe(true);
});

test('accepts valid Python-style post release version', () => {
expect(isValidVersion('1.2.3-1')).toBe(true);
});

test('does not accept leading "v"', () => {
expect(isValidVersion('v1.2.3')).toBe(false);
});
Expand Down Expand Up @@ -110,6 +114,17 @@
});
});

test('parses a Python-style post release version', () => {
expect(parseVersion('1.2.3-1')).toEqual({
major: 1,
minor: 2,
patch: 3,
// we misinterpret the post release number as `pre` but this is fine as we
// have specific checks for what we consider a preview release
pre: '1',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth a comment that it misinterprets this -- but it's ok as long as we don't utilize this function for python in the same way

});
});

test('does not parse an invalid version', () => {
expect(parseVersion('v1.2')).toBeNull();
});
Expand All @@ -120,9 +135,12 @@
});

describe('isPreviewRelease', () => {
test('accepts semver preview release', () => {
expect(isPreviewRelease('2.3.4-preview1')).toBe(true);
});
test.each(['preview', 'pre', 'alpha.0', 'beta', 'rc.1', 'dev'])(
'accepts semver preview release',
previewSuffix => {
expect(isPreviewRelease(`2.3.4-${previewSuffix}1`)).toBe(true);
}
);

test('accepts Python-style preview release', () => {
expect(isPreviewRelease('2.3.4rc0')).toBe(true);
Expand All @@ -135,6 +153,10 @@
test('does not accept non-release strings', () => {
expect(isPreviewRelease('4-preview')).toBe(false);
});

test('does not accept Python-style post release', () => {
expect(isPreviewRelease('1.2.3-1')).toBe(false);
});
});

describe('versionGreaterOrEqualThan', () => {
Expand Down Expand Up @@ -183,8 +205,8 @@
});

test('can compare pre parts', () => {
const v1 = parseVersion('1.2.3-1')!;

Check warning on line 208 in src/utils/__tests__/version.test.ts

View workflow job for this annotation

GitHub Actions / Lint fixes

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
const v2 = parseVersion('1.2.3-2')!;

Check warning on line 209 in src/utils/__tests__/version.test.ts

View workflow job for this annotation

GitHub Actions / Lint fixes

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
expect(versionGreaterOrEqualThan(v1, v2)).toBe(false);
expect(versionGreaterOrEqualThan(v2, v1)).toBe(true);
});
Expand Down
Loading