|
1 | 1 | import * as ChangeLogManager from './update-changelog'; |
2 | 2 |
|
3 | | -const uncategorizedChangelog = `# Changelog |
| 3 | + |
| 4 | +const emptyChangelog = `# Changelog |
4 | 5 | All notable changes to this project will be documented in this file. |
5 | 6 |
|
6 | 7 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), |
7 | 8 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). |
8 | 9 |
|
9 | 10 | ## [Unreleased] |
10 | 11 |
|
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 | 12 | [Unreleased]: https://github.com/ExampleUsernameOrOrganization/ExampleRepository/ |
18 | 13 | `; |
19 | 14 |
|
20 | 15 | describe('updateChangelog', () => { |
21 | | - it('should contain conventional support mappings categorization', async () => { |
22 | | - // Call updateChangelog, which internally calls the mocked getNewChangeEntries |
| 16 | + let getNewChangeEntriesSpy: jest.SpyInstance; |
| 17 | + |
| 18 | + beforeEach(() => { |
| 19 | + // Setup the spy and mock before each test |
| 20 | + // Assuming getNewChangeEntries returns a Promise<string[]> |
| 21 | + getNewChangeEntriesSpy = jest.spyOn(ChangeLogManager, 'getNewChangeEntries') |
| 22 | + .mockResolvedValue([ |
| 23 | + 'fix: fixed a major bug', |
| 24 | + 'feat: introduced a new feature', |
| 25 | + 'unknown: some non-conventional commit' |
| 26 | + ]); |
| 27 | + }); |
| 28 | + |
| 29 | + afterEach(() => { |
| 30 | + // Restore the original function after each test |
| 31 | + getNewChangeEntriesSpy.mockRestore(); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should contain conventional support mappings categorization when autoCategorize is true', async () => { |
23 | 35 | const result = await ChangeLogManager.updateChangelog({ |
24 | | - changelogContent: uncategorizedChangelog, |
| 36 | + changelogContent: emptyChangelog, |
25 | 37 | currentVersion: '1.0.0', |
26 | | - repoUrl: |
27 | | - 'https://github.com/ExampleUsernameOrOrganization/ExampleRepository', |
| 38 | + repoUrl: 'https://github.com/ExampleUsernameOrOrganization/ExampleRepository', |
28 | 39 | isReleaseCandidate: true, |
29 | 40 | autoCategorize: true, |
30 | 41 | }); |
31 | 42 |
|
32 | | - console.log(result); |
33 | | - |
34 | | - // Verify that some of the commits are included in the result |
35 | 43 | expect(result).toContain('### Fixed'); |
| 44 | + expect(result).toContain('### Added'); |
| 45 | + expect(result).not.toContain('### Uncategorized'); |
36 | 46 | }); |
37 | 47 |
|
38 | | - it('should not contain conventional support mappings categorization', async () => { |
39 | | - // Call updateChangelog, which internally calls the mocked getNewChangeEntries |
| 48 | + it('should not contain conventional support mappings categorization when autoCategorize is false', async () => { |
40 | 49 | const result = await ChangeLogManager.updateChangelog({ |
41 | | - changelogContent: uncategorizedChangelog, |
| 50 | + changelogContent: emptyChangelog, |
42 | 51 | currentVersion: '1.0.0', |
43 | | - repoUrl: |
44 | | - 'https://github.com/ExampleUsernameOrOrganization/ExampleRepository', |
| 52 | + repoUrl: 'https://github.com/ExampleUsernameOrOrganization/ExampleRepository', |
45 | 53 | isReleaseCandidate: true, |
46 | 54 | autoCategorize: false, |
47 | 55 | }); |
48 | 56 |
|
49 | | - // Verify that some of the commits are included in the result |
50 | 57 | expect(result).toContain('### Uncategorized'); |
51 | 58 | expect(result).not.toContain('### Fixed'); |
| 59 | + expect(result).not.toContain('### Added'); |
52 | 60 | }); |
53 | 61 | }); |
0 commit comments