generated from mrchief/npm-package-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
141 lines (132 loc) · 4.12 KB
/
index.test.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const filter = require('./')
describe('index', () => {
let commits
beforeEach(() => {
commits = [
{
type: 'revert',
scope: null,
subject: 'feat(): amazing new module',
header: 'revert: feat(): amazing new module\n',
body: 'This reverts commit 56185b7356766d2b30cfa2406b257080272e0b7a.\n',
footer: null,
notes: [],
references: [],
revert: {
header: 'feat(): amazing new module',
hash: '56185b7356766d2b30cfa2406b257080272e0b7a',
body: null,
},
hash: '789d898b5f8422d7f65cc25135af2c1a95a125ac\n',
raw: {
type: 'revert',
scope: null,
subject: 'feat(): amazing new module',
header: 'revert: feat(): amazing new module\n',
body: 'This reverts commit 56185b7356766d2b30cfa2406b257080272e0b7a.\n',
footer: null,
notes: [],
references: [],
revert: {
header: 'feat(): amazing new module',
hash: '56185b7356766d2b30cfa2406b257080272e0b7a',
body: null,
},
hash: '789d898b5f8422d7f65cc25135af2c1a95a125ac\n',
},
},
{
type: 'Features',
scope: null,
subject: '[excludeMe]: wow',
header: 'amazing new module\n',
body: null,
footer: 'BREAKING CHANGE: Not backward compatible.\n',
notes: [],
references: [],
revert: null,
hash: '56185b',
raw: {
type: 'feat',
scope: null,
subject: 'amazing new module',
header: 'feat(): amazing new module\n',
body: null,
footer: 'BREAKING CHANGE: Not backward compatible.\n',
notes: [],
references: [],
revert: null,
hash: '56185b7356766d2b30cfa2406b257080272e0b7a\n',
},
},
{
type: 'What',
scope: null,
subject: '[excludeme]: new feature',
header: 'feat(): new feature\n',
body: null,
footer: null,
notes: [],
references: [],
revert: null,
hash: '815a3f0',
raw: {
type: 'feat',
scope: null,
subject: 'new feature',
header: 'feat(): new feature\n',
body: null,
footer: null,
notes: [],
references: [],
revert: null,
hash: '815a3f0717bf1dfce007bd076420c609504edcf3\n',
},
},
{
type: 'Chores',
scope: null,
subject: 'first commit',
header: 'chore: first commit\n',
body: null,
footer: null,
notes: [],
references: [],
revert: null,
hash: '74a3e4d6d25',
raw: {
type: 'chore',
scope: null,
subject: 'first commit',
header: 'chore: first commit\n',
body: null,
footer: null,
notes: [],
references: [],
revert: null,
hash: '74a3e4d6d25dee2c0d6483a0a3887417728cbe0a\n',
},
},
]
})
it('should filter commits by pattern', () => {
const expected = [commits[1]]
const filteredCommits = filter({ commits, field: 'subject', pattern: '[excludeMe]' })
expect(filteredCommits).toEqual(expect.not.arrayContaining(expected))
})
it('should filter commits by regex', () => {
const expected = [commits[1], commits[2]]
const filteredCommits = filter({ commits, field: 'subject', pattern: /\[excludeMe\]/i })
expect(filteredCommits).toEqual(expect.not.arrayContaining(expected))
})
it('should include commits when include flag is true', () => {
const expected = [commits[1], commits[2]]
const filteredCommits = filter({ commits, field: 'subject', pattern: '[excludeMe]', include: true })
expect(filteredCommits).toEqual(expect.arrayContaining(expected))
})
it('should filter with multiple fields', () => {
const expected = [commits[1]]
const filteredCommits = filter({ commits, field: ['body', 'footer'], pattern: 'BREAKING CHANGE', include: true })
expect(filteredCommits).toEqual(expect.arrayContaining(expected))
})
})