Skip to content

check if changelogDir is not null #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions __tests__/changelog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,33 @@ describe('Changelog', () => {
expect(fs.existsSync(settings.changelogFilePath)).toBe(true)
expect(fileContent).toEqual(expectedFileContent)
})

it('Verifies changelog is saved to default file', async () => {
const settings = {} as Settings
settings.changelogFilePath = 'CHANGELOG.md'

const gitLog: GitCommit[] = [
new GitCommit('295b513', 'Third commit'),
new GitCommit('0dad212', 'Second commit'),
new GitCommit('80913ba', 'First commit')
]
const changelog = new Changelog(settings)
changelog.write(gitLog)

// Read created CHANGELOG.md
const fileContent: string = fs.readFileSync(settings.changelogFilePath).toString()

const expectedFileContent: string = [
'# Changelog',
'295b513 Third commit',
'0dad212 Second commit',
'80913ba First commit'
].join('\n')

// Verifies file is created and contains expected data
expect(fs.existsSync(settings.changelogFilePath)).toBe(true)
expect(fileContent).toEqual(expectedFileContent)

io.rmRF(settings.changelogFilePath)
})
})
2 changes: 1 addition & 1 deletion src/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class Changelog {
})

const changelogDir: string = path.parse(this.settings.changelogFilePath).dir
if (!fs.existsSync(changelogDir)) {
if (changelogDir && !fs.existsSync(changelogDir)) {
fs.mkdirSync(changelogDir)
}

Expand Down