apisurf
Version:
Analyze API surface changes between npm package versions to catch breaking changes
71 lines (70 loc) • 2.84 kB
JavaScript
import { describe, it, expect } from '@jest/globals';
import { calculateSemverImpact } from './calculateSemverImpact.js';
describe('calculateSemverImpact', () => {
it('should return major bump for breaking changes', () => {
const packages = [{
name: 'test-package',
path: './test',
breakingChanges: [{
type: 'export-removed',
description: 'Removed export',
before: 'function'
}],
nonBreakingChanges: []
}];
const impact = calculateSemverImpact(packages);
expect(impact.minimumBump).toBe('major');
expect(impact.reason).toBe('Breaking changes detected');
});
it('should return minor bump for non-breaking changes only', () => {
const packages = [{
name: 'test-package',
path: './test',
breakingChanges: [],
nonBreakingChanges: [{
type: 'export-added',
description: 'Added export',
details: 'newFunction'
}]
}];
const impact = calculateSemverImpact(packages);
expect(impact.minimumBump).toBe('minor');
expect(impact.reason).toBe('New features added');
});
it('should return patch bump for no changes', () => {
const packages = [{
name: 'test-package',
path: './test',
breakingChanges: [],
nonBreakingChanges: []
}];
const impact = calculateSemverImpact(packages);
expect(impact.minimumBump).toBe('patch');
expect(impact.reason).toBe('No changes detected');
});
it('should prioritize breaking changes over non-breaking changes', () => {
const packages = [{
name: 'test-package',
path: './test',
breakingChanges: [{
type: 'export-removed',
description: 'Removed export',
before: 'function'
}],
nonBreakingChanges: [{
type: 'export-added',
description: 'Added export',
details: 'newFunction'
}]
}];
const impact = calculateSemverImpact(packages);
expect(impact.minimumBump).toBe('major');
expect(impact.reason).toBe('Breaking changes detected');
});
it('should handle empty packages array', () => {
const packages = [];
const impact = calculateSemverImpact(packages);
expect(impact.minimumBump).toBe('patch');
expect(impact.reason).toBe('No changes detected');
});
});