diff --git a/__tests__/utils.test.ts b/__tests__/utils.test.ts new file mode 100644 index 0000000..851a2cb --- /dev/null +++ b/__tests__/utils.test.ts @@ -0,0 +1,25 @@ +import {describe, test, expect} from '@jest/globals' +import {extractVersion} from '../src/utils' + +// shows how the runner will run a javascript action with env / stdout protocol +describe('extractVersion', () => { + test('should return the version if the branch convention is valid', () => { + expect(extractVersion('hotfix/1.2.3')).toBe('1.2.3') + expect(extractVersion('hotfix/v1.2.3')).toBe('1.2.3') + expect(extractVersion('hotfix/ktx/v1.2.3')).toBe('1.2.3') + + expect(extractVersion('release/1.2.3')).toBe('1.2.3') + expect(extractVersion('release/v1.2.3')).toBe('1.2.3') + expect(extractVersion('release/ktx/v1.2.3')).toBe('1.2.3') + }) + + test('Should return an empty string if the branch convention is invalid', () => { + expect(extractVersion('v1.2.3')).toBe('') + expect(extractVersion('1.2.3')).toBe('') + expect(extractVersion('unknown/1.2.3')).toBe('') + expect(extractVersion('hotfixx/1.2.3')).toBe('') + expect(extractVersion('hotfixx/v1.2.3')).toBe('') + expect(extractVersion('releases/1.2.3')).toBe('') + expect(extractVersion('releases/v1.2.3')).toBe('') + }) +})