diff --git a/packages/ckeditor5-dev-env/lib/release-tools/utils/changelog.js b/packages/ckeditor5-dev-env/lib/release-tools/utils/changelog.js index 3dbe3b13a..f40a576e2 100644 --- a/packages/ckeditor5-dev-env/lib/release-tools/utils/changelog.js +++ b/packages/ckeditor5-dev-env/lib/release-tools/utils/changelog.js @@ -30,7 +30,7 @@ const utils = { version = version.replace( /^v/, '' ); const changelog = utils.getChangelog( cwd ).replace( utils.changelogHeader, '\n' ); - const match = changelog.match( new RegExp( `\\n(## \\[?${ version }\\]?[\\s\\S]+?)(?:\\n## \\[|$)` ) ); + const match = changelog.match( new RegExp( `\\n(## \\[?${ version }\\]?[\\s\\S]+?)(?:\\n## \\[?|$)` ) ); if ( !match || !match[ 1 ] ) { return null; diff --git a/packages/ckeditor5-dev-env/tests/release-tools/utils/changelog.js b/packages/ckeditor5-dev-env/tests/release-tools/utils/changelog.js index fe504e24c..fff15578d 100644 --- a/packages/ckeditor5-dev-env/tests/release-tools/utils/changelog.js +++ b/packages/ckeditor5-dev-env/tests/release-tools/utils/changelog.js @@ -37,10 +37,11 @@ describe( 'dev-env/release-tools/utils', () => { '* Cloned the main module. ([abcd123](https://github.com))' ].join( '\n' ); - const changelog = - `## [0.1.0](https://github.com) (2017-01-13) - -${ expectedChangelog }`; + const changelog = [ + '## [0.1.0](https://github.com) (2017-01-13)', + '', + expectedChangelog + ].join( '\n' ); const currentChangelogStub = sandbox.stub( utils, 'getChangelog' ) .returns( utils.changelogHeader + changelog ); @@ -58,10 +59,11 @@ ${ expectedChangelog }`; '* Cloned the main module. ([abcd123](https://github.com))' ].join( '\n' ); - const changelog = - `## 0.1.0 (2017-01-13) - -${ expectedChangelog }`; + const changelog = [ + '## 0.1.0 (2017-01-13)', + '', + expectedChangelog + ].join( '\n' ); const currentChangelogStub = sandbox.stub( utils, 'getChangelog' ) .returns( utils.changelogHeader + changelog ); @@ -73,25 +75,27 @@ ${ expectedChangelog }`; } ); it( 'returns changes between tags', () => { - const expectedChangelog = -`### Features - -* Cloned the main module. ([abcd123](https://github.com)) - -### BREAKING CHANGE - -* Bump the major!`; - - const changelog = -`## [1.0.0](https://github.com/) (2017-01-13) - -${ expectedChangelog } - -## [0.1.0](https://github.com) (2017-01-13) - -### Features + const expectedChangelog = [ + '### Features', + '', + '* Cloned the main module. ([abcd123](https://github.com))', + '', + '### BREAKING CHANGE', + '', + '* Bump the major!' + ].join( '\n' ); -* Cloned the main module. ([abcd123](https://github.com))`; + const changelog = [ + '## [1.0.0](https://github.com/) (2017-01-13)', + '', + expectedChangelog, + '', + '## [0.1.0](https://github.com) (2017-01-13)', + '', + '### Features', + '', + '* Cloned the main module. ([abcd123](https://github.com))' + ].join( '\n' ); const currentChangelogStub = sandbox.stub( utils, 'getChangelog' ) .returns( utils.changelogHeader + changelog ); @@ -103,12 +107,13 @@ ${ expectedChangelog } } ); it( 'returns null if cannot find changes for the specified version', () => { - const changelog = -`## [0.1.0](https://github.com) (2017-01-13) - -### Features - -* Cloned the main module. ([abcd123](https://github.com))`; + const changelog = [ + '## [0.1.0](https://github.com) (2017-01-13)', + '', + '### Features', + '', + '* Cloned the main module. ([abcd123](https://github.com))' + ].join( '\n' ); sandbox.stub( utils, 'getChangelog' ) .returns( utils.changelogHeader + changelog ); @@ -116,21 +121,36 @@ ${ expectedChangelog } expect( utils.getChangesForVersion( 'v1.0.0' ) ).to.equal( null ); } ); - it( 'does not leak or stop too early', () => { - const changelog = -`## [0.3.0](https://github.com) (2017-01-13) - -3 - -Some text ## [like a release header] - -## [0.2.0](https://github.com) (2017-01-13) + it( 'works when date is not specified', () => { + const changelog = [ + '## 0.3.0', + '', + 'Foo' + ].join( '\n' ); -2 + sandbox.stub( utils, 'getChangelog' ) + .returns( utils.changelogHeader + changelog ); -## [0.1.0](https://github.com) (2017-01-13) + expect( utils.getChangesForVersion( 'v0.3.0' ) ) + .to.equal( 'Foo' ); + } ); -1`; + it( 'captures correct range of changes (headers are URLs)', () => { + const changelog = [ + '## [0.3.0](https://github.com) (2017-01-13)', + '', + '3', + '', + 'Some text ## [like a release header]', + '', + '## [0.2.0](https://github.com) (2017-01-13)', + '', + '2', + '', + '## [0.1.0](https://github.com) (2017-01-13)', + '', + '1' + ].join( '\n' ); sandbox.stub( utils, 'getChangelog' ) .returns( utils.changelogHeader + changelog ); @@ -142,17 +162,99 @@ Some text ## [like a release header] .to.equal( '2' ); } ); - it( 'works when date is not specified', () => { - const changelog = -`## 0.3.0 + it( 'captures correct range of changes (headers are plain text, "the initial" release check)', () => { + const changelog = [ + 'Changelog', + '=========', + '', + '## 1.0.2 (2022-02-22)', + '', + '### Other changes', + '', + '* Other change for `1.0.2`.', + '', + '', + '## 1.0.1 (2022-02-22)', + '', + '### Other changes', + '', + '* Other change for `1.0.1`.', + '', + '', + '## 1.0.0 (2022-02-22)', + '', + 'This is the initial release.' + ].join( '\n' ); -Foo`; + sandbox.stub( utils, 'getChangelog' ).returns( utils.changelogHeader + changelog ); - sandbox.stub( utils, 'getChangelog' ) - .returns( utils.changelogHeader + changelog ); + expect( utils.getChangesForVersion( '1.0.0' ) ).to.equal( 'This is the initial release.' ); + } ); - expect( utils.getChangesForVersion( 'v0.3.0' ) ) - .to.equal( 'Foo' ); + it( 'captures correct range of changes (headers are plain text, "middle" version check)', () => { + const changelog = [ + 'Changelog', + '=========', + '', + '## 1.0.2 (2022-02-22)', + '', + '### Other changes', + '', + '* Other change for `1.0.2`.', + '', + '', + '## 1.0.1 (2022-02-22)', + '', + '### Other changes', + '', + '* Other change for `1.0.1`.', + '', + '', + '## 1.0.0 (2022-02-22)', + '', + 'This is the initial release.' + ].join( '\n' ); + + sandbox.stub( utils, 'getChangelog' ).returns( utils.changelogHeader + changelog ); + + expect( utils.getChangesForVersion( '1.0.1' ) ).to.equal( [ + '### Other changes', + '', + '* Other change for `1.0.1`.' + ].join( '\n' ) ); + } ); + + it( 'captures correct range of changes (headers are plain text, "the latest" check)', () => { + const changelog = [ + 'Changelog', + '=========', + '', + '## 1.0.2 (2022-02-22)', + '', + '### Other changes', + '', + '* Other change for `1.0.2`.', + '', + '', + '## 1.0.1 (2022-02-22)', + '', + '### Other changes', + '', + '* Other change for `1.0.1`.', + '', + '', + '## 1.0.0 (2022-02-22)', + '', + 'This is the initial release.' + ].join( '\n' ); + + sandbox.stub( utils, 'getChangelog' ).returns( utils.changelogHeader + changelog ); + + expect( utils.getChangesForVersion( '1.0.2' ) ).to.equal( [ + '### Other changes', + '', + '* Other change for `1.0.2`.' + ].join( '\n' ) ); } ); } );