UNPKG

apisurf

Version:

Analyze API surface changes between npm package versions to catch breaking changes

66 lines (65 loc) 3.44 kB
import { getVersionBumpType } from './getVersionBumpType.js'; describe('getVersionBumpType', () => { describe('major version bumps', () => { it('should detect major version bump', () => { expect(getVersionBumpType('1.0.0', '2.0.0')).toBe('major'); expect(getVersionBumpType('0.5.3', '1.0.0')).toBe('major'); expect(getVersionBumpType('10.2.1', '11.0.0')).toBe('major'); }); it('should detect major version bump with minor/patch changes', () => { expect(getVersionBumpType('1.2.3', '2.1.0')).toBe('major'); expect(getVersionBumpType('1.2.3', '2.0.1')).toBe('major'); }); }); describe('minor version bumps', () => { it('should detect minor version bump', () => { expect(getVersionBumpType('1.0.0', '1.1.0')).toBe('minor'); expect(getVersionBumpType('2.3.5', '2.4.0')).toBe('minor'); expect(getVersionBumpType('0.10.0', '0.11.0')).toBe('minor'); }); it('should detect minor version bump with patch changes', () => { expect(getVersionBumpType('1.2.3', '1.3.1')).toBe('minor'); expect(getVersionBumpType('1.2.3', '1.3.10')).toBe('minor'); }); }); describe('patch version bumps', () => { it('should detect patch version bump', () => { expect(getVersionBumpType('1.0.0', '1.0.1')).toBe('patch'); expect(getVersionBumpType('2.3.5', '2.3.6')).toBe('patch'); expect(getVersionBumpType('0.0.10', '0.0.11')).toBe('patch'); }); }); describe('prerelease versions', () => { it('should detect prerelease versions', () => { expect(getVersionBumpType('1.0.0-alpha', '1.0.0-beta')).toBe('prerelease'); expect(getVersionBumpType('1.0.0', '1.0.1-rc.1')).toBe('prerelease'); expect(getVersionBumpType('1.0.0-beta.1', '1.0.0')).toBe('prerelease'); }); it('should handle prerelease with version bumps correctly', () => { expect(getVersionBumpType('1.0.0', '1.0.1-alpha')).toBe('prerelease'); expect(getVersionBumpType('1.0.0-beta', '1.1.0')).toBe('minor'); expect(getVersionBumpType('1.0.0-beta', '2.0.0')).toBe('major'); }); }); describe('edge cases', () => { it('should return unknown for invalid versions', () => { expect(getVersionBumpType('1.0', '1.1')).toBe('unknown'); expect(getVersionBumpType('1', '2')).toBe('unknown'); expect(getVersionBumpType('invalid', 'version')).toBe('unknown'); expect(getVersionBumpType('', '')).toBe('unknown'); }); it('should return unknown for same versions', () => { expect(getVersionBumpType('1.0.0', '1.0.0')).toBe('unknown'); expect(getVersionBumpType('2.3.4', '2.3.4')).toBe('unknown'); }); it('should return unknown for downgrade versions', () => { expect(getVersionBumpType('2.0.0', '1.0.0')).toBe('unknown'); expect(getVersionBumpType('1.2.0', '1.1.0')).toBe('unknown'); expect(getVersionBumpType('1.0.2', '1.0.1')).toBe('unknown'); }); it('should handle versions with more than 3 parts', () => { expect(getVersionBumpType('1.0.0.0', '1.0.0.1')).toBe('patch'); expect(getVersionBumpType('1.0.0.Final', '1.0.1.Final')).toBe('patch'); }); }); });