|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { getSemverUpdateType } from '~/utils/semVer'; |
| 3 | + |
| 4 | +const currentVersion = { major: 1, minor: 2, patch: 3 }; |
| 5 | + |
| 6 | +describe('getSemverUpdateType', () => { |
| 7 | + it('returns "major" when new major version is higher', () => { |
| 8 | + expect( |
| 9 | + getSemverUpdateType(currentVersion, { major: 2, minor: 0, patch: 0 }), |
| 10 | + ).toBe('major'); |
| 11 | + expect( |
| 12 | + getSemverUpdateType(currentVersion, { major: 2, minor: 2, patch: 3 }), |
| 13 | + ).toBe('major'); |
| 14 | + }); |
| 15 | + |
| 16 | + it('returns "minor" when major is the same and new minor version is higher', () => { |
| 17 | + expect( |
| 18 | + getSemverUpdateType(currentVersion, { major: 1, minor: 3, patch: 0 }), |
| 19 | + ).toBe('minor'); |
| 20 | + expect( |
| 21 | + getSemverUpdateType(currentVersion, { major: 1, minor: 3, patch: 3 }), |
| 22 | + ).toBe('minor'); |
| 23 | + }); |
| 24 | + |
| 25 | + it('returns "patch" when major and minor are the same and new patch version is higher', () => { |
| 26 | + expect( |
| 27 | + getSemverUpdateType(currentVersion, { major: 1, minor: 2, patch: 4 }), |
| 28 | + ).toBe('patch'); |
| 29 | + }); |
| 30 | + |
| 31 | + it('returns null when versions are identical', () => { |
| 32 | + expect( |
| 33 | + getSemverUpdateType(currentVersion, { major: 1, minor: 2, patch: 3 }), |
| 34 | + ).toBe(null); |
| 35 | + }); |
| 36 | + |
| 37 | + it('returns null when new version is lower than current version', () => { |
| 38 | + expect( |
| 39 | + getSemverUpdateType(currentVersion, { major: 1, minor: 2, patch: 2 }), |
| 40 | + ).toBe(null); |
| 41 | + expect( |
| 42 | + getSemverUpdateType(currentVersion, { major: 1, minor: 1, patch: 3 }), |
| 43 | + ).toBe(null); |
| 44 | + expect( |
| 45 | + getSemverUpdateType(currentVersion, { major: 0, minor: 9, patch: 5 }), |
| 46 | + ).toBe(null); |
| 47 | + }); |
| 48 | + |
| 49 | + it('returns correct type when versions differ across all parts', () => { |
| 50 | + // Major is higher |
| 51 | + expect( |
| 52 | + getSemverUpdateType( |
| 53 | + { major: 1, minor: 0, patch: 0 }, |
| 54 | + { major: 2, minor: 1, patch: 1 }, |
| 55 | + ), |
| 56 | + ).toBe('major'); |
| 57 | + // Minor is higher |
| 58 | + expect( |
| 59 | + getSemverUpdateType( |
| 60 | + { major: 1, minor: 1, patch: 0 }, |
| 61 | + { major: 1, minor: 2, patch: 0 }, |
| 62 | + ), |
| 63 | + ).toBe('minor'); |
| 64 | + // Patch is higher |
| 65 | + expect( |
| 66 | + getSemverUpdateType( |
| 67 | + { major: 1, minor: 2, patch: 3 }, |
| 68 | + { major: 1, minor: 2, patch: 4 }, |
| 69 | + ), |
| 70 | + ).toBe('patch'); |
| 71 | + }); |
| 72 | +}); |
0 commit comments