forked from cookpete/auto-changelog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommit-list-helper.js
100 lines (91 loc) · 3.2 KB
/
commit-list-helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const { describe, it } = require('mocha')
const { expect } = require('chai')
const Handlebars = require('handlebars')
describe('commit-list helper', () => {
const commits = [
{ subject: 'Commit 1', message: 'Commit 1\n\nThis is commit 1, nothing special' },
{ subject: 'Commit 2', message: 'Commit 2\n\nBREAKING CHANGE: This commit breaks something' },
{ subject: 'feat: Commit 3', message: 'feat: Commit 3\n\nThis commit adds a feature' }
]
const merges = [
{ commit: { subject: 'Commit 1', message: 'Commit 1\n\nThis is commit 1, nothing special' } },
{ commit: { subject: 'Commit 2', message: 'Commit 2\n\nBREAKING CHANGE: This commit breaks something' } },
{ commit: { subject: 'feat: Commit 3', message: 'feat: Commit 3\n\nThis commit adds a feature' } }
]
it('returns nothing with no commits', () => {
const compile = Handlebars.compile(
'{{#commit-list commits heading="# Heading"}}\n' +
'- {{subject}}\n' +
'{{/commit-list}}'
)
const expected = ''
expect(compile({ commits: [] })).to.equal(expected)
})
it('returns all commits with no options', () => {
const compile = Handlebars.compile(
'{{#commit-list commits heading="# Heading"}}\n' +
'- {{subject}}\n' +
'{{/commit-list}}'
)
const expected =
'# Heading\n\n' +
'- Commit 1\n' +
'- Commit 2\n' +
'- feat: Commit 3\n'
expect(compile({ commits })).to.equal(expected)
})
it('supports subject pattern matching', () => {
const compile = Handlebars.compile(
'{{#commit-list commits heading="# Heading" subject="^feat: "}}\n' +
'- {{subject}}\n' +
'{{/commit-list}}'
)
const expected =
'# Heading\n\n' +
'- feat: Commit 3\n'
expect(compile({ commits })).to.equal(expected)
})
it('supports merge subject pattern matching', () => {
const compile = Handlebars.compile(
'{{#commit-list merges heading="# Heading" subject="^feat: "}}\n' +
'- {{commit.subject}}\n' +
'{{/commit-list}}'
)
const expected =
'# Heading\n\n' +
'- feat: Commit 3\n'
expect(compile({ merges })).to.equal(expected)
})
it('supports message pattern matching', () => {
const compile = Handlebars.compile(
'{{#commit-list commits heading="# Breaking Changes" message="^BREAKING CHANGE: "}}\n' +
'- {{subject}}\n' +
'{{/commit-list}}'
)
const expected =
'# Breaking Changes\n\n' +
'- Commit 2\n'
expect(compile({ commits })).to.equal(expected)
})
it('supports excludes option', () => {
const compile = Handlebars.compile(
'{{#commit-list commits heading="# Heading" exclude="^BREAKING CHANGE: "}}\n' +
'- {{subject}}\n' +
'{{/commit-list}}'
)
const expected =
'# Heading\n\n' +
'- Commit 1\n' +
'- feat: Commit 3\n'
expect(compile({ commits })).to.equal(expected)
})
it('returns nothing if nothing matches', () => {
const compile = Handlebars.compile(
'{{#commit-list commits heading="# Heading" message="A string that never appears"}}\n' +
'- {{subject}}\n' +
'{{/commit-list}}'
)
const expected = ''
expect(compile({ commits })).to.equal(expected)
})
})