import { describe, expect, it } from 'vitest' import { isNewerVersion, nextDevVersion } from '../version.js' describe('nextDevVersion — 4.x finish-version-bumping (from the RELEASED version)', () => { it('release bumps minor and resets patch', () => { expect(nextDevVersion('5.1.0', 'release')).toBe('5.2.0') expect(nextDevVersion('5.0.0', 'release')).toBe('5.1.0') expect(nextDevVersion('4.81.0', 'release')).toBe('4.82.0') }) it('hotfix bumps patch by TWO (patch+1 consumed by the tag, +1 free for next hotfix)', () => { expect(nextDevVersion('5.0.1', 'hotfix')).toBe('5.0.3') expect(nextDevVersion('5.0.0', 'hotfix')).toBe('5.0.2') expect(nextDevVersion('4.81.4', 'hotfix')).toBe('4.81.6') }) it('strips a leading v', () => { expect(nextDevVersion('v5.1.0', 'release')).toBe('5.2.0') expect(nextDevVersion('v5.0.1', 'hotfix')).toBe('5.0.3') }) it('treats unknown branch types like a release (minor bump)', () => { expect(nextDevVersion('5.1.0', 'other')).toBe('5.2.0') }) it('is defensive against short/partial versions', () => { expect(nextDevVersion('5', 'release')).toBe('5.1.0') // 5.0.0 → minor+1 expect(nextDevVersion('5.2', 'hotfix')).toBe('5.2.2') // 5.2.0 → patch+2 }) }) describe('isNewerVersion — a version bump never goes backwards', () => { it('orders numerically, not lexically', () => { expect(isNewerVersion('5.20.0', '5.19.4')).toBe(true) expect(isNewerVersion('5.9.0', '5.10.0')).toBe(false) expect(isNewerVersion('5.19.4', '5.19.2')).toBe(true) }) it('is false on equality — nothing to bump', () => { expect(isNewerVersion('5.20.0', '5.20.0')).toBe(false) }) it('guards the hotfix-after-develop-moved-on case', () => { // A hotfix on 5.19.2 derives 5.19.4, but develop already sits at 5.20.0: // writing it would rewind develop and make the next release republish a // number npm already has. expect(isNewerVersion(nextDevVersion('5.19.2', 'hotfix'), '5.20.0')).toBe(false) // The normal case still bumps. expect(isNewerVersion(nextDevVersion('5.20.0', 'release'), '5.20.0')).toBe(true) }) it('tolerates a leading v and short forms', () => { expect(isNewerVersion('v5.21.0', '5.20.0')).toBe(true) expect(isNewerVersion('5.20', '5.19.9')).toBe(true) }) })