From 89ddc92a05c6b65a2cc798601b0d9c23224ace84 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Mon, 11 Nov 2024 18:13:31 +0100 Subject: [PATCH 1/2] test(utils): Add additional tests for version helper functions --- src/utils/__tests__/version.test.ts | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/utils/__tests__/version.test.ts b/src/utils/__tests__/version.test.ts index c3922d84..cc1c86bd 100644 --- a/src/utils/__tests__/version.test.ts +++ b/src/utils/__tests__/version.test.ts @@ -42,6 +42,10 @@ describe('isValidVersion', () => { 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); }); @@ -110,6 +114,15 @@ describe('parseVersion', () => { }); }); + test('parses a Python-style post release version', () => { + expect(parseVersion('1.2.3-1')).toEqual({ + major: 1, + minor: 2, + patch: 3, + pre: '1', + }); + }); + test('does not parse an invalid version', () => { expect(parseVersion('v1.2')).toBeNull(); }); @@ -120,9 +133,12 @@ describe('parseVersion', () => { }); 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); @@ -135,6 +151,10 @@ describe('isPreviewRelease', () => { 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', () => { From 1bf3795dcb91bdd2f25201d72a36a96ba1e7d51e Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Mon, 11 Nov 2024 18:24:44 +0100 Subject: [PATCH 2/2] add comment --- src/utils/__tests__/version.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/__tests__/version.test.ts b/src/utils/__tests__/version.test.ts index cc1c86bd..dc02a783 100644 --- a/src/utils/__tests__/version.test.ts +++ b/src/utils/__tests__/version.test.ts @@ -119,6 +119,8 @@ describe('parseVersion', () => { 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', }); });