Skip to content

Commit 04564c8

Browse files
committed
unit tests for new code
1 parent 65ef5a1 commit 04564c8

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/update-changelog.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import * as ChangeLogManager from './update-changelog';
2+
3+
const uncategorizedChangelog = `# Changelog
4+
All notable changes to this project will be documented in this file.
5+
6+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
7+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8+
9+
## [Unreleased]
10+
11+
## [1.0.0]
12+
### Uncategorized
13+
- fix: a commit of the type fix patches a bug in your codebase
14+
- feat: a commit of the type feat introduces a new feature to the codebase
15+
- unknown: a commit of the type unknown does not match any of the conventional commit types
16+
17+
[Unreleased]: https://github.com/ExampleUsernameOrOrganization/ExampleRepository/
18+
`;
19+
20+
21+
describe('updateChangelog', () => {
22+
it('should contain conventional support mappings categorization', async () => {
23+
// Call updateChangelog, which internally calls the mocked getNewChangeEntries
24+
const result = await ChangeLogManager.updateChangelog({
25+
changelogContent: uncategorizedChangelog,
26+
currentVersion: '1.0.0',
27+
repoUrl: 'https://github.com/ExampleUsernameOrOrganization/ExampleRepository',
28+
isReleaseCandidate: true,
29+
autoCategorize: true
30+
});
31+
32+
// Verify that some of the commits are included in the result
33+
expect(result).toContain('### Added');
34+
expect(result).toContain('### Fixed');
35+
});
36+
37+
it('should not contain conventional support mappings categorization', async () => {
38+
// Call updateChangelog, which internally calls the mocked getNewChangeEntries
39+
const result = await ChangeLogManager.updateChangelog({
40+
changelogContent: uncategorizedChangelog,
41+
currentVersion: '1.0.0',
42+
repoUrl: 'https://github.com/ExampleUsernameOrOrganization/ExampleRepository',
43+
isReleaseCandidate: true,
44+
autoCategorize: false
45+
});
46+
47+
// Verify that some of the commits are included in the result
48+
expect(result).toContain('### Uncategorized');
49+
expect(result).not.toContain('### Fixed');
50+
});
51+
});

src/update-changelog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ type AddNewCommitsOptions = {
180180
* current git repository.
181181
* @returns A list of new change entries to add to the changelog, based on commits made since the last release.
182182
*/
183-
async function getNewChangeEntries({
183+
export async function getNewChangeEntries({
184184
mostRecentTag,
185185
repoUrl,
186186
loggedPrNumbers,

0 commit comments

Comments
 (0)