1
- import test from 'ava' ;
2
1
import lint from '.' ;
3
2
4
- test ( 'throws without params' , async t => {
5
- const error = await t . throwsAsync ( lint ( ) ) ;
6
- t . is ( error . message , 'Expected a raw commit' ) ;
3
+ test ( 'throws without params' , async ( ) => {
4
+ const error = lint ( ) ;
5
+ await expect ( error ) . rejects . toThrow ( 'Expected a raw commit' ) ;
7
6
} ) ;
8
7
9
- test ( 'throws with empty message' , async t => {
10
- const error = await t . throwsAsync ( lint ( '' ) ) ;
11
- t . is ( error . message , 'Expected a raw commit' ) ;
8
+ test ( 'throws with empty message' , async ( ) => {
9
+ const error = lint ( '' ) ;
10
+ await expect ( error ) . rejects . toThrow ( 'Expected a raw commit' ) ;
12
11
} ) ;
13
12
14
- test ( 'positive on stub message and no rule' , async t => {
13
+ test ( 'positive on stub message and no rule' , async ( ) => {
15
14
const actual = await lint ( 'foo: bar' ) ;
16
- t . true ( actual . valid ) ;
15
+ expect ( actual . valid ) . toBe ( true ) ;
17
16
} ) ;
18
17
19
- test ( 'positive on stub message and adhered rule' , async t => {
18
+ test ( 'positive on stub message and adhered rule' , async ( ) => {
20
19
const actual = await lint ( 'foo: bar' , {
21
20
'type-enum' : [ 2 , 'always' , [ 'foo' ] ]
22
21
} ) ;
23
- t . true ( actual . valid ) ;
22
+ expect ( actual . valid ) . toBe ( true ) ;
24
23
} ) ;
25
24
26
- test ( 'negative on stub message and broken rule' , async t => {
25
+ test ( 'negative on stub message and broken rule' , async ( ) => {
27
26
const actual = await lint ( 'foo: bar' , {
28
27
'type-enum' : [ 2 , 'never' , [ 'foo' ] ]
29
28
} ) ;
30
- t . false ( actual . valid ) ;
29
+ expect ( actual . valid ) . toBe ( false ) ;
31
30
} ) ;
32
31
33
- test ( 'positive on ignored message and broken rule' , async t => {
32
+ test ( 'positive on ignored message and broken rule' , async ( ) => {
34
33
const actual = await lint ( 'Revert "some bogus commit"' , {
35
34
'type-empty' : [ 2 , 'never' ]
36
35
} ) ;
37
- t . true ( actual . valid ) ;
38
- t . is ( actual . input , 'Revert "some bogus commit"' ) ;
36
+ expect ( actual . valid ) . toBe ( true ) ;
37
+ expect ( actual . input ) . toBe ( 'Revert "some bogus commit"' ) ;
39
38
} ) ;
40
39
41
- test ( 'negative on ignored message, disabled ignored messages and broken rule' , async t => {
40
+ test ( 'negative on ignored message, disabled ignored messages and broken rule' , async ( ) => {
42
41
const actual = await lint (
43
42
'Revert "some bogus commit"' ,
44
43
{
@@ -48,10 +47,10 @@ test('negative on ignored message, disabled ignored messages and broken rule', a
48
47
defaultIgnores : false
49
48
}
50
49
) ;
51
- t . false ( actual . valid ) ;
50
+ expect ( actual . valid ) . toBe ( false ) ;
52
51
} ) ;
53
52
54
- test ( 'positive on custom ignored message and broken rule' , async t => {
53
+ test ( 'positive on custom ignored message and broken rule' , async ( ) => {
55
54
const ignoredMessage = 'some ignored custom message' ;
56
55
const actual = await lint (
57
56
ignoredMessage ,
@@ -62,11 +61,11 @@ test('positive on custom ignored message and broken rule', async t => {
62
61
ignores : [ c => c === ignoredMessage ]
63
62
}
64
63
) ;
65
- t . true ( actual . valid ) ;
66
- t . is ( actual . input , ignoredMessage ) ;
64
+ expect ( actual . valid ) . toBe ( true ) ;
65
+ expect ( actual . input ) . toBe ( ignoredMessage ) ;
67
66
} ) ;
68
67
69
- test ( 'positive on stub message and opts' , async t => {
68
+ test ( 'positive on stub message and opts' , async ( ) => {
70
69
const actual = await lint (
71
70
'foo-bar' ,
72
71
{
@@ -79,108 +78,102 @@ test('positive on stub message and opts', async t => {
79
78
}
80
79
}
81
80
) ;
82
- t . true ( actual . valid ) ;
81
+ expect ( actual . valid ) . toBe ( true ) ;
83
82
} ) ;
84
83
85
- test ( 'throws for invalid rule names' , async t => {
86
- const error = await t . throwsAsync (
87
- lint ( 'foo' , { foo : [ 2 , 'always' ] , bar : [ 1 , 'never' ] } )
88
- ) ;
84
+ test ( 'throws for invalid rule names' , async ( ) => {
85
+ const error = lint ( 'foo' , { foo : [ 2 , 'always' ] , bar : [ 1 , 'never' ] } ) ;
89
86
90
- t . is ( error . message . indexOf ( ' Found invalid rule names: foo, bar' ) , 0 ) ;
87
+ await expect ( error ) . rejects . toThrow ( / ^ F o u n d i n v a l i d r u l e n a m e s : f o o , b a r / ) ;
91
88
} ) ;
92
89
93
- test ( 'throws for invalid rule config' , async t => {
94
- const error = await t . throwsAsync (
95
- lint ( 'type(scope): foo' , {
96
- 'type-enum' : 1 ,
97
- 'scope-enum' : { 0 : 2 , 1 : 'never' , 2 : [ 'foo' ] , length : 3 }
98
- } )
99
- ) ;
90
+ test ( 'throws for invalid rule config' , async ( ) => {
91
+ const error = lint ( 'type(scope): foo' , {
92
+ 'type-enum' : 1 ,
93
+ 'scope-enum' : { 0 : 2 , 1 : 'never' , 2 : [ 'foo' ] , length : 3 }
94
+ } ) ;
100
95
101
- t . true ( error . message . indexOf ( 'type-enum must be array' ) > - 1 ) ;
102
- t . true ( error . message . indexOf ( 'scope-enum must be array' ) > - 1 ) ;
96
+ await expect ( error ) . rejects . toThrow ( 'type-enum must be array' ) ;
97
+ await expect ( error ) . rejects . toThrow ( 'scope-enum must be array' ) ;
103
98
} ) ;
104
99
105
- test ( 'allows disable shorthand' , async t => {
106
- await t . notThrowsAsync ( lint ( 'foo' , { 'type-enum' : [ 0 ] , 'scope-enum' : [ 0 ] } ) ) ;
100
+ test ( 'allows disable shorthand' , async ( ) => {
101
+ const result = lint ( 'foo' , { 'type-enum' : [ 0 ] , 'scope-enum' : [ 0 ] } ) ;
102
+
103
+ await expect ( result ) . resolves . toEqual ( {
104
+ errors : [ ] ,
105
+ input : 'foo' ,
106
+ valid : true ,
107
+ warnings : [ ]
108
+ } ) ;
107
109
} ) ;
108
110
109
- test ( 'throws for rule with invalid length' , async t => {
110
- const error = await t . throwsAsync (
111
- lint ( 'type(scope): foo' , { 'scope-enum' : [ 1 , 2 , 3 , 4 ] } )
112
- ) ;
111
+ test ( 'throws for rule with invalid length' , async ( ) => {
112
+ const error = lint ( 'type(scope): foo' , { 'scope-enum' : [ 1 , 2 , 3 , 4 ] } ) ;
113
113
114
- t . true ( error . message . indexOf ( 'scope-enum must be 2 or 3 items long' ) > - 1 ) ;
114
+ await expect ( error ) . rejects . toThrow ( 'scope-enum must be 2 or 3 items long' ) ;
115
115
} ) ;
116
116
117
- test ( 'throws for rule with invalid level' , async t => {
118
- const error = await t . throwsAsync (
119
- lint ( 'type(scope): foo' , {
120
- 'type-enum' : [ '2' , 'always' ] ,
121
- 'header-max-length' : [ { } , 'always' ]
122
- } )
123
- ) ;
124
-
125
- t . true ( error . message . indexOf ( 'rule type-enum must be number' ) > - 1 ) ;
126
- t . true ( error . message . indexOf ( 'rule type-enum must be number' ) > - 1 ) ;
117
+ test ( 'throws for rule with invalid level' , async ( ) => {
118
+ const error = lint ( 'type(scope): foo' , {
119
+ 'type-enum' : [ '2' , 'always' ] ,
120
+ 'header-max-length' : [ { } , 'always' ]
121
+ } ) ;
122
+ await expect ( error ) . rejects . toThrow ( 'rule type-enum must be number' ) ;
123
+ await expect ( error ) . rejects . toThrow ( 'rule header-max-length must be number' ) ;
127
124
} ) ;
128
125
129
- test ( 'throws for rule with out of range level' , async t => {
130
- const error = await t . throwsAsync (
131
- lint ( 'type(scope): foo' , {
132
- 'type-enum' : [ - 1 , 'always' ] ,
133
- 'header-max-length' : [ 3 , 'always' ]
134
- } )
135
- ) ;
126
+ test ( 'throws for rule with out of range level' , async ( ) => {
127
+ const error = lint ( 'type(scope): foo' , {
128
+ 'type-enum' : [ - 1 , 'always' ] ,
129
+ 'header-max-length' : [ 3 , 'always' ]
130
+ } ) ;
136
131
137
- t . true ( error . message . indexOf ( 'rule type-enum must be between 0 and 2' ) > - 1 ) ;
138
- t . true ( error . message . indexOf ( 'rule type-enum must be between 0 and 2' ) > - 1 ) ;
132
+ await expect ( error ) . rejects . toThrow ( 'rule type-enum must be between 0 and 2' ) ;
133
+ await expect ( error ) . rejects . toThrow (
134
+ 'rule header-max-length must be between 0 and 2'
135
+ ) ;
139
136
} ) ;
140
137
141
- test ( 'throws for rule with invalid condition' , async t => {
142
- const error = await t . throwsAsync (
143
- lint ( 'type(scope): foo' , {
144
- 'type-enum' : [ 1 , 2 ] ,
145
- 'header-max-length' : [ 1 , { } ]
146
- } )
147
- ) ;
138
+ test ( 'throws for rule with invalid condition' , async ( ) => {
139
+ const error = lint ( 'type(scope): foo' , {
140
+ 'type-enum' : [ 1 , 2 ] ,
141
+ 'header-max-length' : [ 1 , { } ]
142
+ } ) ;
148
143
149
- t . true ( error . message . indexOf ( 'type-enum must be string' ) > - 1 ) ;
150
- t . true ( error . message . indexOf ( 'header-max-length must be string' ) > - 1 ) ;
144
+ await expect ( error ) . rejects . toThrow ( 'type-enum must be string' ) ;
145
+ await expect ( error ) . rejects . toThrow ( 'header-max-length must be string' ) ;
151
146
} ) ;
152
147
153
- test ( 'throws for rule with out of range condition' , async t => {
154
- const error = await t . throwsAsync (
155
- lint ( 'type(scope): foo' , {
156
- 'type-enum' : [ 1 , 'foo' ] ,
157
- 'header-max-length' : [ 1 , 'bar' ]
158
- } )
159
- ) ;
148
+ test ( 'throws for rule with out of range condition' , async ( ) => {
149
+ const error = lint ( 'type(scope): foo' , {
150
+ 'type-enum' : [ 1 , 'foo' ] ,
151
+ 'header-max-length' : [ 1 , 'bar' ]
152
+ } ) ;
160
153
161
- t . true ( error . message . indexOf ( 'type-enum must be "always" or "never"' ) > - 1 ) ;
162
- t . true (
163
- error . message . indexOf ( 'header-max-length must be "always" or "never"' ) > - 1
154
+ await expect ( error ) . rejects . toThrow ( 'type-enum must be "always" or "never"' ) ;
155
+ await expect ( error ) . rejects . toThrow (
156
+ 'header-max-length must be "always" or "never"'
164
157
) ;
165
158
} ) ;
166
159
167
- test ( 'succeds for issue' , async t => {
160
+ test ( 'succeds for issue' , async ( ) => {
168
161
const report = await lint ( 'somehting #1' , {
169
162
'references-empty' : [ 2 , 'never' ]
170
163
} ) ;
171
164
172
- t . true ( report . valid ) ;
165
+ expect ( report . valid ) . toBe ( true ) ;
173
166
} ) ;
174
167
175
- test ( 'fails for issue' , async t => {
168
+ test ( 'fails for issue' , async ( ) => {
176
169
const report = await lint ( 'somehting #1' , {
177
170
'references-empty' : [ 2 , 'always' ]
178
171
} ) ;
179
172
180
- t . false ( report . valid ) ;
173
+ expect ( report . valid ) . toBe ( false ) ;
181
174
} ) ;
182
175
183
- test ( 'succeds for custom issue prefix' , async t => {
176
+ test ( 'succeds for custom issue prefix' , async ( ) => {
184
177
const report = await lint (
185
178
'somehting REF-1' ,
186
179
{
@@ -193,10 +186,10 @@ test('succeds for custom issue prefix', async t => {
193
186
}
194
187
) ;
195
188
196
- t . true ( report . valid ) ;
189
+ expect ( report . valid ) . toBe ( true ) ;
197
190
} ) ;
198
191
199
- test ( 'fails for custom issue prefix' , async t => {
192
+ test ( 'fails for custom issue prefix' , async ( ) => {
200
193
const report = await lint (
201
194
'somehting #1' ,
202
195
{
@@ -209,10 +202,10 @@ test('fails for custom issue prefix', async t => {
209
202
}
210
203
) ;
211
204
212
- t . false ( report . valid ) ;
205
+ expect ( report . valid ) . toBe ( false ) ;
213
206
} ) ;
214
207
215
- test ( 'fails for custom plugin rule' , async t => {
208
+ test ( 'fails for custom plugin rule' , async ( ) => {
216
209
const report = await lint (
217
210
'somehting #1' ,
218
211
{
@@ -229,10 +222,10 @@ test('fails for custom plugin rule', async t => {
229
222
}
230
223
) ;
231
224
232
- t . false ( report . valid ) ;
225
+ expect ( report . valid ) . toBe ( false ) ;
233
226
} ) ;
234
227
235
- test ( 'passes for custom plugin rule' , async t => {
228
+ test ( 'passes for custom plugin rule' , async ( ) => {
236
229
const report = await lint (
237
230
'somehting #1' ,
238
231
{
@@ -249,31 +242,31 @@ test('passes for custom plugin rule', async t => {
249
242
}
250
243
) ;
251
244
252
- t . true ( report . valid ) ;
245
+ expect ( report . valid ) . toBe ( true ) ;
253
246
} ) ;
254
247
255
- test ( 'returns original message only with commit header' , async t => {
248
+ test ( 'returns original message only with commit header' , async ( ) => {
256
249
const message = 'foo: bar' ;
257
250
const report = await lint ( message ) ;
258
251
259
- t . is ( report . input , message ) ;
252
+ expect ( report . input ) . toBe ( message ) ;
260
253
} ) ;
261
254
262
- test ( 'returns original message with commit header and body' , async t => {
255
+ test ( 'returns original message with commit header and body' , async ( ) => {
263
256
const message = 'foo: bar/n/nFoo bar bizz buzz.' ;
264
257
const report = await lint ( message ) ;
265
258
266
- t . is ( report . input , message ) ;
259
+ expect ( report . input ) . toBe ( message ) ;
267
260
} ) ;
268
261
269
- test ( 'returns original message with commit header, body and footer' , async t => {
262
+ test ( 'returns original message with commit header, body and footer' , async ( ) => {
270
263
const message = 'foo: bar/n/nFoo bar bizz buzz./n/nCloses #1' ;
271
264
const report = await lint ( message ) ;
272
265
273
- t . is ( report . input , message ) ;
266
+ expect ( report . input ) . toBe ( message ) ;
274
267
} ) ;
275
268
276
- test ( 'returns original message with commit header, body and footer, parsing comments' , async t => {
269
+ test ( 'returns original message with commit header, body and footer, parsing comments' , async ( ) => {
277
270
const expected = 'foo: bar/n/nFoo bar bizz buzz./n/nCloses #1' ;
278
271
const message = `${ expected } \n\n# Some comment to ignore` ;
279
272
const report = await lint (
@@ -288,5 +281,5 @@ test('returns original message with commit header, body and footer, parsing comm
288
281
}
289
282
) ;
290
283
291
- t . is ( report . input , expected ) ;
284
+ expect ( report . input ) . toBe ( expected ) ;
292
285
} ) ;
0 commit comments