diff --git a/source/lib/create-changelog.test.ts b/source/lib/create-changelog.test.ts index 87a1c304..74c1fa8c 100644 --- a/source/lib/create-changelog.test.ts +++ b/source/lib/create-changelog.test.ts @@ -14,7 +14,7 @@ const changelogOptionsFactory = Factory.define(() => { }; }); -test('contains "Unreleased" with no version number and the formatted date when version was released', (t) => { +test('contains no title when version was not released', (t) => { const createChangelog = createChangelogFactory({ getCurrentDate: () => { return new Date(0); @@ -25,10 +25,11 @@ test('contains "Unreleased" with no version number and the formatted date when v unreleased: true, versionNumber: Maybe.nothing() }); + const changelog = createChangelog(options); - const expectedTitle = '## Unreleased (January 1, 1970)'; + const expected = ''; - t.true(changelog.includes(expectedTitle)); + t.is(changelog, expected); }); test('contains a title with the version number and the formatted date when version was released', (t) => { diff --git a/source/lib/create-changelog.ts b/source/lib/create-changelog.ts index e3538588..5af9ea98 100644 --- a/source/lib/create-changelog.ts +++ b/source/lib/create-changelog.ts @@ -89,13 +89,24 @@ export function createChangelogFactory(dependencies: Dependencies): CreateChange const { getCurrentDate, packageInfo } = dependencies; const dateFormat = getConfigValueFromPackageInfo(packageInfo, 'dateFormat', defaultDateFormat); + function createChangelogTitle(options: ChangelogOptions): string { + const { unreleased } = options; + + if (unreleased) { + return ''; + } + + const date = formatDate(getCurrentDate(), dateFormat, { locale: enLocale }); + const title = `## ${options.versionNumber.value} (${date})`; + + return `${title}\n\n`; + } + return function createChangelog(options) { - const { validLabels, mergedPullRequests, githubRepo, unreleased } = options; + const { validLabels, mergedPullRequests, githubRepo } = options; const groupedPullRequests = groupByLabel(mergedPullRequests); - const date = formatDate(getCurrentDate(), dateFormat, { locale: enLocale }); - const title = unreleased ? `## Unreleased (${date})` : `## ${options.versionNumber.value} (${date})`; - let changelog = `${title}\n\n`; + let changelog = createChangelogTitle(options); for (const [label, displayLabel] of validLabels) { const pullRequests = groupedPullRequests[label];