diff --git a/src/__functional__/changefile/readChangeFiles.test.ts b/src/__functional__/changefile/readChangeFiles.test.ts index 7b26027e3..de582c340 100644 --- a/src/__functional__/changefile/readChangeFiles.test.ts +++ b/src/__functional__/changefile/readChangeFiles.test.ts @@ -9,6 +9,7 @@ import { readChangeFiles } from '../../changefile/readChangeFiles'; import { BeachballOptions } from '../../types/BeachballOptions'; import type { Repository } from '../../__fixtures__/repository'; import { getDefaultOptions } from '../../options/getDefaultOptions'; +import { ChangeInfo } from '../../types/ChangeInfo'; describe('readChangeFiles', () => { let repositoryFactory: RepositoryFactory; @@ -129,4 +130,51 @@ describe('readChangeFiles', () => { expect(changeSet).toHaveLength(1); expect(logs.mocks.warn).not.toHaveBeenCalled(); }); + + it('runs transform.changeFiles functions if provided', async () => { + const editedComment: string = 'Edited comment for testing'; + repo = monoRepoFactory.cloneRepository(); + + const options = getOptions({ + command: 'change', + transform: { + changeFiles: (changeFile, changeFilePath, { command }) => { + // For test, we will be changing the comment based on the package name + if ((changeFile as ChangeInfo).packageName === 'foo') { + (changeFile as ChangeInfo).comment = editedComment; + (changeFile as ChangeInfo).command = command; + } + return changeFile as ChangeInfo; + }, + }, + changelog: { + groups: [ + { + masterPackageName: 'foo', + changelogPath: repo.pathTo('packages/foo'), + include: ['packages/foo', 'packages/bar'], + }, + ], + }, + }); + + repo.commitChange('foo'); + generateChangeFiles([{ packageName: 'foo', comment: 'comment 1' }], options); + + repo.commitChange('bar'); + generateChangeFiles([{ packageName: 'bar', comment: 'comment 2' }], options); + + const packageInfos = getPackageInfos(repo.rootPath); + const changes = readChangeFiles(options, packageInfos); + + // Verify that the comment of only the intended change file is changed + for (const { change, changeFile } of changes) { + if (changeFile.startsWith('foo')) { + expect(change.comment).toBe(editedComment); + expect(change.command).toEqual('change'); + } else { + expect(change.comment).toBe('comment 2'); + } + } + }); }); diff --git a/src/__functional__/changelog/writeChangelog.test.ts b/src/__functional__/changelog/writeChangelog.test.ts index afe2c4bb1..a62500dc0 100644 --- a/src/__functional__/changelog/writeChangelog.test.ts +++ b/src/__functional__/changelog/writeChangelog.test.ts @@ -8,7 +8,7 @@ import { writeChangelog } from '../../changelog/writeChangelog'; import { getPackageInfos } from '../../monorepo/getPackageInfos'; import { readChangeFiles } from '../../changefile/readChangeFiles'; import { BeachballOptions } from '../../types/BeachballOptions'; -import { ChangeFileInfo, ChangeInfo } from '../../types/ChangeInfo'; +import { ChangeFileInfo } from '../../types/ChangeInfo'; import type { Repository } from '../../__fixtures__/repository'; import { getDefaultOptions } from '../../options/getDefaultOptions'; @@ -296,51 +296,4 @@ describe('writeChangelog', () => { // Validate grouped changelog for foo and bar packages expect(readChangelogMd(repo.pathTo('packages/foo'))).toMatchSnapshot(); }); - - it('runs transform.changeFiles functions if provided', async () => { - const editedComment: string = 'Edited comment for testing'; - repo = monoRepoFactory.cloneRepository(); - - const options = getOptions({ - command: 'change', - transform: { - changeFiles: (changeFile, changeFilePath, { command }) => { - // For test, we will be changing the comment based on the package name - if ((changeFile as ChangeInfo).packageName === 'foo') { - (changeFile as ChangeInfo).comment = editedComment; - (changeFile as ChangeInfo).command = command; - } - return changeFile as ChangeInfo; - }, - }, - changelog: { - groups: [ - { - masterPackageName: 'foo', - changelogPath: repo.pathTo('packages/foo'), - include: ['packages/foo', 'packages/bar'], - }, - ], - }, - }); - - repo.commitChange('foo'); - generateChangeFiles([getChange('foo', 'comment 1')], options); - - repo.commitChange('bar'); - generateChangeFiles([getChange('bar', 'comment 2')], options); - - const packageInfos = getPackageInfos(repo.rootPath); - const changes = readChangeFiles(options, packageInfos); - - // Verify that the comment of only the intended change file is changed - for (const { change, changeFile } of changes) { - if (changeFile.startsWith('foo')) { - expect(change.comment).toBe(editedComment); - expect(change.command).toEqual('change'); - } else { - expect(change.comment).toBe('comment 2'); - } - } - }); });