Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feat/init-and-update
Browse files Browse the repository at this point in the history
  • Loading branch information
bpetetot committed Oct 14, 2018
2 parents 0b20404 + 08b2af3 commit 1847cf1
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 28 deletions.
10 changes: 9 additions & 1 deletion packages/gitmoji-changelog-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ function makeGroups(commits) {
.map(({ group, label }) => ({
group,
label,
commits: commits.filter(commit => commit.group === group),
commits: commits
.filter(commit => commit.group === group)
.sort((first, second) => {
if (!first.emoji) return -1

const emojiCriteria = first.emoji.localeCompare(second.emoji)
if (emojiCriteria !== 0) return emojiCriteria
return first.date.localeCompare(second.date)
}),
}))
.filter(group => group.commits.length)
}
Expand Down
82 changes: 55 additions & 27 deletions packages/gitmoji-changelog-core/src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,43 @@ const gitSemverTags = require('git-semver-tags')
const { generateChangelog } = require('./index')

const sparklesCommit = {
hash: 'c40ee8669ba7ea5151adc2942fa8a7fc98d9e23f',
hash: 'c40ee8669ba7ea5151adc2942fa8a7fc98d9e23a',
date: '2018-08-28T10:06:00+02:00',
subject: ':sparkles: Upgrade brand new feature',
body: 'Waouh this is awesome 2',
}

const recycleCommit = {
hash: 'c40ee8669ba7ea5151adc2942fa8a7fc98d9e23c',
date: '2018-08-28T10:07:00+02:00',
date: '2018-08-01T10:07:00+02:00',
subject: ':recycle: Upgrade brand new feature',
body: 'Waouh this is awesome 3',
}

const secondRecycleCommit = {
hash: 'c40ee8669ba7ea5151adc2942fa8a7fc98d9e23d',
date: '2018-08-30T10:07:00+02:00',
subject: ':recycle: Upgrade another brand new feature',
body: 'Waouh this is awesome 4',
}

const lipstickCommit = {
hash: 'c40ee8669ba7ea5151adc2942fa8a7fc98d9e23e',
date: '2018-08-10T10:07:00+02:00',
subject: ':lipstick: Change graphics for a feature',
body: 'Waouh this is awesome 5',
}

const secondLipstickCommit = {
hash: 'c40ee8669ba7ea5151adc2942fa8a7fc98d9e23f',
date: '2018-08-18T10:07:00+02:00',
subject: ':lipstick: Change more graphics for a feature',
body: 'Waouh this is awesome 6',
}

describe('changelog', () => {
it('should generate changelog for next release', async () => {
mockCommits()
mockGroups()

gitSemverTags.mockImplementation(cb => cb(null, []))

Expand All @@ -31,17 +52,19 @@ describe('changelog', () => {
version: 'next',
groups: [
{
group: 'changed',
label: 'Changed',
commits: [expect.objectContaining(recycleCommit)],
group: 'added',
label: 'Added',
commits: expect.arrayContaining([
expect.objectContaining(sparklesCommit),
]),
},
],
},
])
})

it('should generate changelog for all tags', async () => {
mockCommits()
mockGroups()

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

Expand All @@ -50,12 +73,17 @@ describe('changelog', () => {
expect(changes).toEqual([
{
version: '1.0.0',
date: '2018-08-28',
date: '2018-08-30',
groups: [
{
group: 'added',
label: 'Added',
commits: [expect.objectContaining(sparklesCommit)],
group: 'changed',
label: 'Changed',
commits: [
expect.objectContaining(lipstickCommit),
expect.objectContaining(secondLipstickCommit),
expect.objectContaining(recycleCommit),
expect.objectContaining(secondRecycleCommit),
],
},
],
},
Expand All @@ -64,6 +92,7 @@ describe('changelog', () => {

it('should generate empty changelog if no commits', async () => {
mockNoCommits()

gitSemverTags.mockImplementation(cb => cb(null, []))

const { changes } = await generateChangelog({ mode: 'incremental', release: 'next' })
Expand All @@ -75,25 +104,19 @@ describe('changelog', () => {
jest.mock('git-raw-commits')
jest.mock('git-semver-tags')

function mockCommits() {
function mockGroup(commits) {
gitRawCommits.mockImplementationOnce(() => {
const stream = require('stream')
const readable = new stream.Readable()
const {
hash, date, subject, body,
} = recycleCommit
readable.push(`\n${hash}\n${date}\n${subject}\n${body}\n`)
readable.push(null)
readable.emit('close')
return readable
})
gitRawCommits.mockImplementationOnce(() => {
const stream = require('stream')
const readable = new stream.Readable()
const {
hash, date, subject, body,
} = sparklesCommit
readable.push(`\n${hash}\n${date}\n${subject}\n${body}\n`)
commits.forEach(commit => {
const {
hash,
date,
subject,
body,
} = commit
readable.push(`\n${hash}\n${date}\n${subject}\n${body}\n`)
})
readable.push(null)
readable.emit('close')
return readable
Expand All @@ -111,3 +134,8 @@ function mockNoCommits() {
return readable
})
}

function mockGroups() {
mockGroup([sparklesCommit])
mockGroup([recycleCommit, secondRecycleCommit, lipstickCommit, secondLipstickCommit])
}

0 comments on commit 1847cf1

Please sign in to comment.