forked from cookpete/auto-changelog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatches-helper.js
74 lines (69 loc) · 2.08 KB
/
matches-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
const { describe, it } = require('mocha')
const { expect } = require('chai')
const Handlebars = require('handlebars')
const releases = require('./data/releases')
describe('matches helper', () => {
const compileCommits = (matches) => Handlebars.compile(
'{{#each releases}}\n' +
'{{#each commits}}\n' +
matches +
'{{/each}}\n' +
'{{/each}}',
{ noEscape: true }
)
it('matches on field value', () => {
const matches =
'{{#matches href "12c0624"}}\n' +
'- {{message}}\n' +
'{{/matches}}\n'
const expected =
'- Commit that fixes nothing with `backticks` and <html>\n'
expect(compileCommits(matches)({ releases })).to.equal(expected)
})
it('matches with case insensitive flag', () => {
const matches =
'{{#matches author "example" flags="i"}}\n' +
'- {{shorthash}}\n' +
'{{/matches}}\n'
const expected =
'- b0b3040\n' +
'- 12c0624\n' +
'- e9a43b2\n' +
'- 158fdde\n'
expect(compileCommits(matches)({ releases })).to.equal(expected)
})
it('provides non-matching conditional', () => {
const matches =
'{{#matches shorthash "e9a43b2"}}\n' +
'- HIT {{date}}\n' +
'{{else}}\n' +
'- MISS {{date}}\n' +
'{{/matches}}\n'
const expected =
'- MISS 2015-12-29T21:57:19.000Z\n' +
'- MISS 2015-12-29T21:18:19.000Z\n' +
'- HIT 2015-12-29T21:19:19.000Z\n' +
'- MISS 2015-12-14T17:06:12.000Z\n'
expect(compileCommits(matches)({ releases })).to.equal(expected)
})
it('matches on multiline content', () => {
const multiReleases = [{
commits: [
{
shorthash: 'c0f25d7',
message: 'Hello\n\nWorld\n\nBREAKING CHANGE: mock break\n\nsome more text'
}, {
shorthash: '12cd728',
message: 'Nope'
}
]
}]
const matches =
'{{#matches message "BREAKING CHANGE"}}\n' +
'- {{shorthash}}\n' +
'{{/matches}}\n'
const expected =
'- c0f25d7\n'
expect(compileCommits(matches)({ releases: multiReleases })).to.equal(expected)
})
})