Skip to content

Commit

Permalink
🐛 Remove empty versions (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabienjuif authored Oct 27, 2018
1 parent 7fd3730 commit 64ac5a7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/gitmoji-changelog-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async function generateVersions(tags) {
})
.map(generateVersion)
)
.then(changes => changes.sort((c1, c2) => {
.then(versions => versions.sort((c1, c2) => {
if (c1.version === 'next') return -1
if (c2.version === 'next') return 1
return semverCompare(c2.version, c1.version)
Expand Down Expand Up @@ -133,7 +133,7 @@ async function generateChangelog(options = {}) {
repository,
lastVersion: sanitizeVersion(lastTag),
},
changes,
changes: changes.filter(({ groups }) => groups.length),
}
}

Expand Down
15 changes: 15 additions & 0 deletions packages/gitmoji-changelog-core/src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,21 @@ describe('changelog', () => {
)
expect(gitRawCommits).toHaveBeenCalledWith(expect.objectContaining({ from: '', to: 'v1.0.0' }))
})

it('should filter empty groups out', async () => {
mockGroup([sparklesCommit])
mockGroup([recycleCommit])
mockGroup([]) // empty group
mockGroup([lipstickCommit])

gitSemverTags.mockImplementation(cb => cb(null, ['v1.0.0', '1.0.0', 'v1.1.1']))

const { changes } = await generateChangelog({ mode: 'init' })

// inputs has 4 group (4 versions)
// but output should only has 3, since the 3rd is empty
expect(changes).toHaveLength(3)
})
})

jest.mock('git-raw-commits')
Expand Down

0 comments on commit 64ac5a7

Please sign in to comment.