Skip to content

Commit cb2cca8

Browse files
committed
Move readChangeFiles test to correct file
1 parent 938c6a6 commit cb2cca8

2 files changed

Lines changed: 49 additions & 48 deletions

File tree

src/__functional__/changefile/readChangeFiles.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { readChangeFiles } from '../../changefile/readChangeFiles';
99
import { BeachballOptions } from '../../types/BeachballOptions';
1010
import type { Repository } from '../../__fixtures__/repository';
1111
import { getDefaultOptions } from '../../options/getDefaultOptions';
12+
import { ChangeInfo } from '../../types/ChangeInfo';
1213

1314
describe('readChangeFiles', () => {
1415
let repositoryFactory: RepositoryFactory;
@@ -129,4 +130,51 @@ describe('readChangeFiles', () => {
129130
expect(changeSet).toHaveLength(1);
130131
expect(logs.mocks.warn).not.toHaveBeenCalled();
131132
});
133+
134+
it('runs transform.changeFiles functions if provided', async () => {
135+
const editedComment: string = 'Edited comment for testing';
136+
repo = monoRepoFactory.cloneRepository();
137+
138+
const options = getOptions({
139+
command: 'change',
140+
transform: {
141+
changeFiles: (changeFile, changeFilePath, { command }) => {
142+
// For test, we will be changing the comment based on the package name
143+
if ((changeFile as ChangeInfo).packageName === 'foo') {
144+
(changeFile as ChangeInfo).comment = editedComment;
145+
(changeFile as ChangeInfo).command = command;
146+
}
147+
return changeFile as ChangeInfo;
148+
},
149+
},
150+
changelog: {
151+
groups: [
152+
{
153+
masterPackageName: 'foo',
154+
changelogPath: repo.pathTo('packages/foo'),
155+
include: ['packages/foo', 'packages/bar'],
156+
},
157+
],
158+
},
159+
});
160+
161+
repo.commitChange('foo');
162+
generateChangeFiles([{ packageName: 'foo', comment: 'comment 1' }], options);
163+
164+
repo.commitChange('bar');
165+
generateChangeFiles([{ packageName: 'bar', comment: 'comment 2' }], options);
166+
167+
const packageInfos = getPackageInfos(repo.rootPath);
168+
const changes = readChangeFiles(options, packageInfos);
169+
170+
// Verify that the comment of only the intended change file is changed
171+
for (const { change, changeFile } of changes) {
172+
if (changeFile.startsWith('foo')) {
173+
expect(change.comment).toBe(editedComment);
174+
expect(change.command).toEqual('change');
175+
} else {
176+
expect(change.comment).toBe('comment 2');
177+
}
178+
}
179+
});
132180
});

src/__functional__/changelog/writeChangelog.test.ts

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { writeChangelog } from '../../changelog/writeChangelog';
88
import { getPackageInfos } from '../../monorepo/getPackageInfos';
99
import { readChangeFiles } from '../../changefile/readChangeFiles';
1010
import { BeachballOptions } from '../../types/BeachballOptions';
11-
import { ChangeFileInfo, ChangeInfo } from '../../types/ChangeInfo';
11+
import { ChangeFileInfo } from '../../types/ChangeInfo';
1212
import type { Repository } from '../../__fixtures__/repository';
1313
import { getDefaultOptions } from '../../options/getDefaultOptions';
1414

@@ -296,51 +296,4 @@ describe('writeChangelog', () => {
296296
// Validate grouped changelog for foo and bar packages
297297
expect(readChangelogMd(repo.pathTo('packages/foo'))).toMatchSnapshot();
298298
});
299-
300-
it('runs transform.changeFiles functions if provided', async () => {
301-
const editedComment: string = 'Edited comment for testing';
302-
repo = monoRepoFactory.cloneRepository();
303-
304-
const options = getOptions({
305-
command: 'change',
306-
transform: {
307-
changeFiles: (changeFile, changeFilePath, { command }) => {
308-
// For test, we will be changing the comment based on the package name
309-
if ((changeFile as ChangeInfo).packageName === 'foo') {
310-
(changeFile as ChangeInfo).comment = editedComment;
311-
(changeFile as ChangeInfo).command = command;
312-
}
313-
return changeFile as ChangeInfo;
314-
},
315-
},
316-
changelog: {
317-
groups: [
318-
{
319-
masterPackageName: 'foo',
320-
changelogPath: repo.pathTo('packages/foo'),
321-
include: ['packages/foo', 'packages/bar'],
322-
},
323-
],
324-
},
325-
});
326-
327-
repo.commitChange('foo');
328-
generateChangeFiles([getChange('foo', 'comment 1')], options);
329-
330-
repo.commitChange('bar');
331-
generateChangeFiles([getChange('bar', 'comment 2')], options);
332-
333-
const packageInfos = getPackageInfos(repo.rootPath);
334-
const changes = readChangeFiles(options, packageInfos);
335-
336-
// Verify that the comment of only the intended change file is changed
337-
for (const { change, changeFile } of changes) {
338-
if (changeFile.startsWith('foo')) {
339-
expect(change.comment).toBe(editedComment);
340-
expect(change.command).toEqual('change');
341-
} else {
342-
expect(change.comment).toBe('comment 2');
343-
}
344-
}
345-
});
346299
});

0 commit comments

Comments
 (0)