Skip to content

Commit 07ece41

Browse files
authored
fix action failing if using default chagelog-path (#10)
* check if changelogDir is not null * add test to test default CHANGELOG.md without folder
1 parent dc13ff9 commit 07ece41

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

__tests__/changelog.test.ts

+29
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,33 @@ describe('Changelog', () => {
4242
expect(fs.existsSync(settings.changelogFilePath)).toBe(true)
4343
expect(fileContent).toEqual(expectedFileContent)
4444
})
45+
46+
it('Verifies changelog is saved to default file', async () => {
47+
const settings = {} as Settings
48+
settings.changelogFilePath = 'CHANGELOG.md'
49+
50+
const gitLog: GitCommit[] = [
51+
new GitCommit('295b513', 'Third commit'),
52+
new GitCommit('0dad212', 'Second commit'),
53+
new GitCommit('80913ba', 'First commit')
54+
]
55+
const changelog = new Changelog(settings)
56+
changelog.write(gitLog)
57+
58+
// Read created CHANGELOG.md
59+
const fileContent: string = fs.readFileSync(settings.changelogFilePath).toString()
60+
61+
const expectedFileContent: string = [
62+
'# Changelog',
63+
'295b513 Third commit',
64+
'0dad212 Second commit',
65+
'80913ba First commit'
66+
].join('\n')
67+
68+
// Verifies file is created and contains expected data
69+
expect(fs.existsSync(settings.changelogFilePath)).toBe(true)
70+
expect(fileContent).toEqual(expectedFileContent)
71+
72+
io.rmRF(settings.changelogFilePath)
73+
})
4574
})

src/changelog.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class Changelog {
1818
})
1919

2020
const changelogDir: string = path.parse(this.settings.changelogFilePath).dir
21-
if (!fs.existsSync(changelogDir)) {
21+
if (changelogDir && !fs.existsSync(changelogDir)) {
2222
fs.mkdirSync(changelogDir)
2323
}
2424

0 commit comments

Comments
 (0)