1
1
import { promisify } from 'util' ;
2
2
import test from 'ava' ;
3
+ import { stub } from 'sinon' ;
3
4
import commitAnalyzer from '../lib/index' ;
4
5
6
+ test . beforeEach ( t => {
7
+ const log = stub ( ) ;
8
+ t . context . log = log ;
9
+ t . context . logger = { log} ;
10
+ } ) ;
11
+
5
12
test ( 'Parse with "conventional-changelog-angular" by default' , async t => {
6
13
const commits = [ { message : 'fix(scope1): First fix' } , { message : 'feat(scope2): Second feature' } ] ;
7
- const releaseType = await promisify ( commitAnalyzer ) ( { } , { commits} ) ;
14
+ const releaseType = await promisify ( commitAnalyzer ) ( { } , { commits, logger : t . context . logger } ) ;
8
15
9
16
t . is ( releaseType , 'minor' ) ;
17
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 0 ] . message ) ) ;
18
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'patch' ) ) ;
19
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 1 ] . message ) ) ;
20
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'minor' ) ) ;
21
+ t . true ( t . context . log . calledWith ( 'Analysis of %s commits complete: %s release' , 2 , 'minor' ) ) ;
10
22
} ) ;
11
23
12
24
test ( 'Accept "preset" option' , async t => {
13
25
const commits = [ { message : 'Fix: First fix (fixes #123)' } , { message : 'Update: Second feature (fixes #456)' } ] ;
14
- const releaseType = await promisify ( commitAnalyzer ) ( { preset : 'eslint' } , { commits} ) ;
26
+ const releaseType = await promisify ( commitAnalyzer ) ( { preset : 'eslint' } , { commits, logger : t . context . logger } ) ;
15
27
16
28
t . is ( releaseType , 'minor' ) ;
29
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 0 ] . message ) ) ;
30
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'patch' ) ) ;
31
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 1 ] . message ) ) ;
32
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'minor' ) ) ;
33
+ t . true ( t . context . log . calledWith ( 'Analysis of %s commits complete: %s release' , 2 , 'minor' ) ) ;
17
34
} ) ;
18
35
19
36
test ( 'Accept "config" option' , async t => {
20
37
const commits = [ { message : 'Fix: First fix (fixes #123)' } , { message : 'Update: Second feature (fixes #456)' } ] ;
21
- const releaseType = await promisify ( commitAnalyzer ) ( { config : 'conventional-changelog-eslint' } , { commits} ) ;
38
+ const releaseType = await promisify ( commitAnalyzer ) (
39
+ { config : 'conventional-changelog-eslint' } ,
40
+ { commits, logger : t . context . logger }
41
+ ) ;
22
42
23
43
t . is ( releaseType , 'minor' ) ;
44
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 0 ] . message ) ) ;
45
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'patch' ) ) ;
46
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 1 ] . message ) ) ;
47
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'minor' ) ) ;
48
+ t . true ( t . context . log . calledWith ( 'Analysis of %s commits complete: %s release' , 2 , 'minor' ) ) ;
24
49
} ) ;
25
50
26
51
test ( 'Accept a "parseOpts" object as option' , async t => {
@@ -30,10 +55,15 @@ test('Accept a "parseOpts" object as option', async t => {
30
55
] ;
31
56
const releaseType = await promisify ( commitAnalyzer ) (
32
57
{ parserOpts : { headerPattern : / ^ # # ( .* ?) # # ( .* ) $ / , headerCorrespondence : [ 'tag' , 'shortDesc' ] } } ,
33
- { commits}
58
+ { commits, logger : t . context . logger }
34
59
) ;
35
60
36
61
t . is ( releaseType , 'minor' ) ;
62
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 0 ] . message ) ) ;
63
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'patch' ) ) ;
64
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 1 ] . message ) ) ;
65
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'minor' ) ) ;
66
+ t . true ( t . context . log . calledWith ( 'Analysis of %s commits complete: %s release' , 2 , 'minor' ) ) ;
37
67
} ) ;
38
68
39
69
test ( 'Accept a partial "parseOpts" object as option' , async t => {
@@ -43,34 +73,57 @@ test('Accept a partial "parseOpts" object as option', async t => {
43
73
config : 'conventional-changelog-eslint' ,
44
74
parserOpts : { headerPattern : / ^ # # ( .* ?) # # ( .* ) $ / , headerCorrespondence : [ 'type' , 'shortDesc' ] } ,
45
75
} ,
46
- { commits}
76
+ { commits, logger : t . context . logger }
47
77
) ;
48
78
49
79
t . is ( releaseType , 'patch' ) ;
80
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 0 ] . message ) ) ;
81
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'patch' ) ) ;
82
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 1 ] . message ) ) ;
83
+ t . true ( t . context . log . calledWith ( 'The commit should not trigger a release' ) ) ;
84
+ t . true ( t . context . log . calledWith ( 'Analysis of %s commits complete: %s release' , 2 , 'patch' ) ) ;
50
85
} ) ;
51
86
52
87
test ( 'Accept a "releaseRules" option that reference a requierable module' , async t => {
53
88
const commits = [ { message : 'fix(scope1): First fix' } , { message : 'feat(scope2): Second feature' } ] ;
54
- const releaseType = await promisify ( commitAnalyzer ) ( { releaseRules : './test/fixtures/release-rules' } , { commits} ) ;
89
+ const releaseType = await promisify ( commitAnalyzer ) (
90
+ { releaseRules : './test/fixtures/release-rules' } ,
91
+ { commits, logger : t . context . logger }
92
+ ) ;
55
93
56
94
t . is ( releaseType , 'minor' ) ;
95
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 0 ] . message ) ) ;
96
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'patch' ) ) ;
97
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 1 ] . message ) ) ;
98
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'minor' ) ) ;
99
+ t . true ( t . context . log . calledWith ( 'Analysis of %s commits complete: %s release' , 2 , 'minor' ) ) ;
57
100
} ) ;
58
101
59
102
test ( 'Return "major" if there is a breaking change, using default releaseRules' , async t => {
60
103
const commits = [
61
104
{ message : 'Fix: First fix (fixes #123)' } ,
62
105
{ message : 'Update: Second feature (fixes #456) \n\n BREAKING CHANGE: break something' } ,
63
106
] ;
64
- const releaseType = await promisify ( commitAnalyzer ) ( { preset : 'eslint' } , { commits} ) ;
107
+ const releaseType = await promisify ( commitAnalyzer ) ( { preset : 'eslint' } , { commits, logger : t . context . logger } ) ;
65
108
66
109
t . is ( releaseType , 'major' ) ;
110
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 0 ] . message ) ) ;
111
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'patch' ) ) ;
112
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 1 ] . message ) ) ;
113
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'major' ) ) ;
114
+ t . true ( t . context . log . calledWith ( 'Analysis of %s commits complete: %s release' , 2 , 'major' ) ) ;
67
115
} ) ;
68
116
69
117
test ( 'Return "patch" if there is only types set to "patch", using default releaseRules' , async t => {
70
118
const commits = [ { message : 'fix: First fix (fixes #123)' } , { message : 'perf: perf improvement' } ] ;
71
- const releaseType = await promisify ( commitAnalyzer ) ( { } , { commits} ) ;
119
+ const releaseType = await promisify ( commitAnalyzer ) ( { } , { commits, logger : t . context . logger } ) ;
72
120
73
121
t . is ( releaseType , 'patch' ) ;
122
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 0 ] . message ) ) ;
123
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'patch' ) ) ;
124
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 1 ] . message ) ) ;
125
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'patch' ) ) ;
126
+ t . true ( t . context . log . calledWith ( 'Analysis of %s commits complete: %s release' , 2 , 'patch' ) ) ;
74
127
} ) ;
75
128
76
129
test ( 'Allow to use regex in "releaseRules" configuration' , async t => {
@@ -80,27 +133,42 @@ test('Allow to use regex in "releaseRules" configuration', async t => {
80
133
preset : 'eslint' ,
81
134
releaseRules : [ { tag : 'Chore' , release : 'patch' } , { message : '/README/' , release : 'minor' } ] ,
82
135
} ,
83
- { commits}
136
+ { commits, logger : t . context . logger }
84
137
) ;
85
138
86
139
t . is ( releaseType , 'minor' ) ;
140
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 0 ] . message ) ) ;
141
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'minor' ) ) ;
142
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 1 ] . message ) ) ;
143
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'minor' ) ) ;
144
+ t . true ( t . context . log . calledWith ( 'Analysis of %s commits complete: %s release' , 2 , 'minor' ) ) ;
87
145
} ) ;
88
146
89
147
test ( 'Return "null" if no rule match' , async t => {
90
148
const commits = [ { message : 'doc: doc update' } , { message : 'chore: Chore' } ] ;
91
- const releaseType = await promisify ( commitAnalyzer ) ( { } , { commits} ) ;
149
+ const releaseType = await promisify ( commitAnalyzer ) ( { } , { commits, logger : t . context . logger } ) ;
92
150
93
151
t . is ( releaseType , null ) ;
152
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 0 ] . message ) ) ;
153
+ t . true ( t . context . log . calledWith ( 'The commit should not trigger a release' ) ) ;
154
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 1 ] . message ) ) ;
155
+ t . true ( t . context . log . calledWith ( 'The commit should not trigger a release' ) ) ;
156
+ t . true ( t . context . log . calledWith ( 'Analysis of %s commits complete: %s release' , 2 , 'no' ) ) ;
94
157
} ) ;
95
158
96
159
test ( 'Process rules in order and apply highest match' , async t => {
97
160
const commits = [ { message : 'Chore: First chore (fixes #123)' } , { message : 'Docs: update README (fixes #456)' } ] ;
98
161
const releaseType = await promisify ( commitAnalyzer ) (
99
162
{ preset : 'eslint' , releaseRules : [ { tag : 'Chore' , release : 'minor' } , { tag : 'Chore' , release : 'patch' } ] } ,
100
- { commits}
163
+ { commits, logger : t . context . logger }
101
164
) ;
102
165
103
166
t . is ( releaseType , 'minor' ) ;
167
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 0 ] . message ) ) ;
168
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'minor' ) ) ;
169
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 1 ] . message ) ) ;
170
+ t . true ( t . context . log . calledWith ( 'The commit should not trigger a release' ) ) ;
171
+ t . true ( t . context . log . calledWith ( 'Analysis of %s commits complete: %s release' , 2 , 'minor' ) ) ;
104
172
} ) ;
105
173
106
174
test ( 'Process rules in order and apply highest match from config even if default has an higher match' , async t => {
@@ -110,27 +178,30 @@ test('Process rules in order and apply highest match from config even if default
110
178
] ;
111
179
const releaseType = await promisify ( commitAnalyzer ) (
112
180
{ preset : 'eslint' , releaseRules : [ { tag : 'Chore' , release : 'patch' } , { breaking : true , release : 'minor' } ] } ,
113
- { commits}
181
+ { commits, logger : t . context . logger }
114
182
) ;
115
183
116
184
t . is ( releaseType , 'minor' ) ;
185
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 0 ] . message ) ) ;
186
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'patch' ) ) ;
187
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 1 ] . message ) ) ;
188
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'minor' ) ) ;
189
+ t . true ( t . context . log . calledWith ( 'Analysis of %s commits complete: %s release' , 2 , 'minor' ) ) ;
117
190
} ) ;
118
191
119
192
test ( 'Use default "releaseRules" if none of provided match' , async t => {
120
193
const commits = [ { message : 'Chore: First chore' } , { message : 'Update: new feature' } ] ;
121
194
const releaseType = await promisify ( commitAnalyzer ) (
122
195
{ preset : 'eslint' , releaseRules : [ { tag : 'Chore' , release : 'patch' } ] } ,
123
- { commits}
196
+ { commits, logger : t . context . logger }
124
197
) ;
125
198
126
199
t . is ( releaseType , 'minor' ) ;
127
- } ) ;
128
-
129
- test ( 'Ignore malformatted commits and process valid ones' , async t => {
130
- const commits = [ { message : 'fix(scope1): First fix' } , { message : 'Feature => Invalid message' } ] ;
131
- const releaseType = await promisify ( commitAnalyzer ) ( { } , { commits} ) ;
132
-
133
- t . is ( releaseType , 'patch' ) ;
200
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 0 ] . message ) ) ;
201
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'patch' ) ) ;
202
+ t . true ( t . context . log . calledWith ( 'Analyzing commit: %s' , commits [ 1 ] . message ) ) ;
203
+ t . true ( t . context . log . calledWith ( 'The release type for the commit is %s' , 'minor' ) ) ;
204
+ t . true ( t . context . log . calledWith ( 'Analysis of %s commits complete: %s release' , 2 , 'minor' ) ) ;
134
205
} ) ;
135
206
136
207
test ( 'Throw error if "preset" doesn`t exist' , async t => {
@@ -155,7 +226,9 @@ test('Throw error if "releaseRules" option reference a requierable module that i
155
226
156
227
test ( 'Throw error if "config" doesn`t exist' , async t => {
157
228
const commits = [ { message : 'Fix: First fix (fixes #123)' } , { message : 'Update: Second feature (fixes #456)' } ] ;
158
- const error = await t . throws ( promisify ( commitAnalyzer ) ( { config : 'unknown-config' } , { commits} ) ) ;
229
+ const error = await t . throws (
230
+ promisify ( commitAnalyzer ) ( { config : 'unknown-config' } , { commits, logger : t . context . logger } )
231
+ ) ;
159
232
160
233
t . is ( error . code , 'MODULE_NOT_FOUND' ) ;
161
234
} ) ;
@@ -174,7 +247,7 @@ test('Re-Throw error from "conventional-changelog-parser"', async t => {
174
247
175
248
test ( 'Accept an undefined "pluginConfig"' , async t => {
176
249
const commits = [ { message : 'fix(scope1): First fix' } , { message : 'feat(scope2): Second feature' } ] ;
177
- const releaseType = await promisify ( commitAnalyzer ) ( undefined , { commits} ) ;
250
+ const releaseType = await promisify ( commitAnalyzer ) ( undefined , { commits, logger : t . context . logger } ) ;
178
251
179
252
t . is ( releaseType , 'minor' ) ;
180
253
} ) ;
0 commit comments