Skip to content

Commit

Permalink
Move readChangeFiles test to correct file
Browse files Browse the repository at this point in the history
  • Loading branch information
ecraig12345 committed Sep 6, 2024
1 parent 938c6a6 commit cb2cca8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 48 deletions.
48 changes: 48 additions & 0 deletions src/__functional__/changefile/readChangeFiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}
}
});
});
49 changes: 1 addition & 48 deletions src/__functional__/changelog/writeChangelog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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');
}
}
});
});

0 comments on commit cb2cca8

Please sign in to comment.