UNPKG

apisurf

Version:

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

66 lines (65 loc) 3.37 kB
import { detectSemverViolation } from './detectSemverViolation.js'; describe('detectSemverViolation', () => { describe('major version requirement', () => { it('should detect violation when patch is shipped instead of major', () => { const result = detectSemverViolation('1.0.0', '1.0.1', 'major'); expect(result.hasViolation).toBe(true); expect(result.actualBump).toBe('patch'); expect(result.requiredBump).toBe('major'); }); it('should detect violation when minor is shipped instead of major', () => { const result = detectSemverViolation('1.0.0', '1.1.0', 'major'); expect(result.hasViolation).toBe(true); expect(result.actualBump).toBe('minor'); expect(result.requiredBump).toBe('major'); }); it('should not detect violation when major is shipped as required', () => { const result = detectSemverViolation('1.0.0', '2.0.0', 'major'); expect(result.hasViolation).toBe(false); }); }); describe('minor version requirement', () => { it('should detect violation when patch is shipped instead of minor', () => { const result = detectSemverViolation('1.0.0', '1.0.1', 'minor'); expect(result.hasViolation).toBe(true); expect(result.actualBump).toBe('patch'); expect(result.requiredBump).toBe('minor'); }); it('should not detect violation when minor is shipped as required', () => { const result = detectSemverViolation('1.0.0', '1.1.0', 'minor'); expect(result.hasViolation).toBe(false); }); it('should not detect violation when major is shipped (exceeds requirement)', () => { const result = detectSemverViolation('1.0.0', '2.0.0', 'minor'); expect(result.hasViolation).toBe(false); }); }); describe('patch version requirement', () => { it('should not detect violation when patch is shipped as required', () => { const result = detectSemverViolation('1.0.0', '1.0.1', 'patch'); expect(result.hasViolation).toBe(false); }); it('should not detect violation when minor is shipped (exceeds requirement)', () => { const result = detectSemverViolation('1.0.0', '1.1.0', 'patch'); expect(result.hasViolation).toBe(false); }); it('should not detect violation when major is shipped (exceeds requirement)', () => { const result = detectSemverViolation('1.0.0', '2.0.0', 'patch'); expect(result.hasViolation).toBe(false); }); }); describe('edge cases', () => { it('should not detect violation for prerelease versions', () => { const result = detectSemverViolation('1.0.0', '1.0.1-alpha', 'major'); expect(result.hasViolation).toBe(false); }); it('should not detect violation for unknown version bumps', () => { const result = detectSemverViolation('1.0', '1.1', 'major'); expect(result.hasViolation).toBe(false); }); it('should not detect violation for same versions', () => { const result = detectSemverViolation('1.0.0', '1.0.0', 'major'); expect(result.hasViolation).toBe(false); }); }); });