import { createRequire } from 'node:module'; import { describe, expect, it } from 'vitest'; const require = createRequire( import.meta.url ); const { calculateVersionBumpFromChangelog } = require( '../common' ); describe( 'calculateVersionBumpFromChangelog', () => { it( 'should return null when no lines provided', () => { expect( calculateVersionBumpFromChangelog( [] ) ).toBe( null ); } ); it( 'should return null when no unreleased header found', () => { expect( calculateVersionBumpFromChangelog( [ 'First line', 'Second line', 'Third line', 'Fourth line', 'Fifth line', ] ) ).toBe( null ); } ); it( 'should return null when Unreleased header found but no entries', () => { expect( calculateVersionBumpFromChangelog( [ 'First line', '## Unreleased', 'Third line', 'Fourth line', 'Fifth line', ] ) ).toBe( null ); } ); it( 'should return patch version Unreleased header and new item detected', () => { expect( calculateVersionBumpFromChangelog( [ 'First line', '## Unreleased', 'Third line', ' - new item added', 'Fifth line', ] ) ).toBe( 'patch' ); } ); it( 'should return enforce higher version bump when new item detected with lower level', () => { expect( calculateVersionBumpFromChangelog( [ 'First line', '## Unreleased', 'Third line', ' - new item added', 'Fifth line', ], 'major' ) ).toBe( 'major' ); } ); it( 'should return major version bump when breaking changes detected', () => { expect( calculateVersionBumpFromChangelog( [ 'First line', '## Unreleased', '### Breaking Changes', ' - new item added', 'Fifth line', ] ) ).toBe( 'major' ); } ); it( 'should have no effect to use stable release heading on stable package', () => { expect( calculateVersionBumpFromChangelog( [ 'First line', '## Unreleased', '### Stable Release', 'This package is now considered stable.', 'Fifth line', ], 'patch', '1.0.0' ) ).toBe( 'patch' ); } ); describe( 'prerelease versions', () => { it( 'should not bump the major even if breaking changes detected', () => { expect( calculateVersionBumpFromChangelog( [ 'First line', '## Unreleased', '### Breaking Changes', ' - new item added', 'Fifth line', ], 'patch', '0.1.0' ) ).toBe( 'minor' ); } ); it( 'should bump the major when stable release heading detected', () => { expect( calculateVersionBumpFromChangelog( [ 'First line', '## Unreleased', '### Stable Release', 'This package is now considered stable.', 'Fifth line', ], 'patch', '0.1.0' ) ).toBe( 'major' ); } ); } ); } );