1- import test from 'ava' ;
21import lint from '.' ;
32
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' ) ;
76} ) ;
87
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' ) ;
1211} ) ;
1312
14- test ( 'positive on stub message and no rule' , async t => {
13+ test ( 'positive on stub message and no rule' , async ( ) => {
1514 const actual = await lint ( 'foo: bar' ) ;
16- t . true ( actual . valid ) ;
15+ expect ( actual . valid ) . toBe ( true ) ;
1716} ) ;
1817
19- test ( 'positive on stub message and adhered rule' , async t => {
18+ test ( 'positive on stub message and adhered rule' , async ( ) => {
2019 const actual = await lint ( 'foo: bar' , {
2120 'type-enum' : [ 2 , 'always' , [ 'foo' ] ]
2221 } ) ;
23- t . true ( actual . valid ) ;
22+ expect ( actual . valid ) . toBe ( true ) ;
2423} ) ;
2524
26- test ( 'negative on stub message and broken rule' , async t => {
25+ test ( 'negative on stub message and broken rule' , async ( ) => {
2726 const actual = await lint ( 'foo: bar' , {
2827 'type-enum' : [ 2 , 'never' , [ 'foo' ] ]
2928 } ) ;
30- t . false ( actual . valid ) ;
29+ expect ( actual . valid ) . toBe ( false ) ;
3130} ) ;
3231
33- test ( 'positive on ignored message and broken rule' , async t => {
32+ test ( 'positive on ignored message and broken rule' , async ( ) => {
3433 const actual = await lint ( 'Revert "some bogus commit"' , {
3534 'type-empty' : [ 2 , 'never' ]
3635 } ) ;
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"' ) ;
3938} ) ;
4039
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 ( ) => {
4241 const actual = await lint (
4342 'Revert "some bogus commit"' ,
4443 {
@@ -48,10 +47,10 @@ test('negative on ignored message, disabled ignored messages and broken rule', a
4847 defaultIgnores : false
4948 }
5049 ) ;
51- t . false ( actual . valid ) ;
50+ expect ( actual . valid ) . toBe ( false ) ;
5251} ) ;
5352
54- test ( 'positive on custom ignored message and broken rule' , async t => {
53+ test ( 'positive on custom ignored message and broken rule' , async ( ) => {
5554 const ignoredMessage = 'some ignored custom message' ;
5655 const actual = await lint (
5756 ignoredMessage ,
@@ -62,11 +61,11 @@ test('positive on custom ignored message and broken rule', async t => {
6261 ignores : [ c => c === ignoredMessage ]
6362 }
6463 ) ;
65- t . true ( actual . valid ) ;
66- t . is ( actual . input , ignoredMessage ) ;
64+ expect ( actual . valid ) . toBe ( true ) ;
65+ expect ( actual . input ) . toBe ( ignoredMessage ) ;
6766} ) ;
6867
69- test ( 'positive on stub message and opts' , async t => {
68+ test ( 'positive on stub message and opts' , async ( ) => {
7069 const actual = await lint (
7170 'foo-bar' ,
7271 {
@@ -79,108 +78,102 @@ test('positive on stub message and opts', async t => {
7978 }
8079 }
8180 ) ;
82- t . true ( actual . valid ) ;
81+ expect ( actual . valid ) . toBe ( true ) ;
8382} ) ;
8483
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' ] } ) ;
8986
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 / ) ;
9188} ) ;
9289
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+ } ) ;
10095
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' ) ;
10398} ) ;
10499
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+ } ) ;
107109} ) ;
108110
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 ] } ) ;
113113
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' ) ;
115115} ) ;
116116
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' ) ;
127124} ) ;
128125
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+ } ) ;
136131
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+ ) ;
139136} ) ;
140137
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+ } ) ;
148143
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' ) ;
151146} ) ;
152147
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+ } ) ;
160153
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"'
164157 ) ;
165158} ) ;
166159
167- test ( 'succeds for issue' , async t => {
160+ test ( 'succeds for issue' , async ( ) => {
168161 const report = await lint ( 'somehting #1' , {
169162 'references-empty' : [ 2 , 'never' ]
170163 } ) ;
171164
172- t . true ( report . valid ) ;
165+ expect ( report . valid ) . toBe ( true ) ;
173166} ) ;
174167
175- test ( 'fails for issue' , async t => {
168+ test ( 'fails for issue' , async ( ) => {
176169 const report = await lint ( 'somehting #1' , {
177170 'references-empty' : [ 2 , 'always' ]
178171 } ) ;
179172
180- t . false ( report . valid ) ;
173+ expect ( report . valid ) . toBe ( false ) ;
181174} ) ;
182175
183- test ( 'succeds for custom issue prefix' , async t => {
176+ test ( 'succeds for custom issue prefix' , async ( ) => {
184177 const report = await lint (
185178 'somehting REF-1' ,
186179 {
@@ -193,10 +186,10 @@ test('succeds for custom issue prefix', async t => {
193186 }
194187 ) ;
195188
196- t . true ( report . valid ) ;
189+ expect ( report . valid ) . toBe ( true ) ;
197190} ) ;
198191
199- test ( 'fails for custom issue prefix' , async t => {
192+ test ( 'fails for custom issue prefix' , async ( ) => {
200193 const report = await lint (
201194 'somehting #1' ,
202195 {
@@ -209,10 +202,10 @@ test('fails for custom issue prefix', async t => {
209202 }
210203 ) ;
211204
212- t . false ( report . valid ) ;
205+ expect ( report . valid ) . toBe ( false ) ;
213206} ) ;
214207
215- test ( 'fails for custom plugin rule' , async t => {
208+ test ( 'fails for custom plugin rule' , async ( ) => {
216209 const report = await lint (
217210 'somehting #1' ,
218211 {
@@ -229,10 +222,10 @@ test('fails for custom plugin rule', async t => {
229222 }
230223 ) ;
231224
232- t . false ( report . valid ) ;
225+ expect ( report . valid ) . toBe ( false ) ;
233226} ) ;
234227
235- test ( 'passes for custom plugin rule' , async t => {
228+ test ( 'passes for custom plugin rule' , async ( ) => {
236229 const report = await lint (
237230 'somehting #1' ,
238231 {
@@ -249,31 +242,31 @@ test('passes for custom plugin rule', async t => {
249242 }
250243 ) ;
251244
252- t . true ( report . valid ) ;
245+ expect ( report . valid ) . toBe ( true ) ;
253246} ) ;
254247
255- test ( 'returns original message only with commit header' , async t => {
248+ test ( 'returns original message only with commit header' , async ( ) => {
256249 const message = 'foo: bar' ;
257250 const report = await lint ( message ) ;
258251
259- t . is ( report . input , message ) ;
252+ expect ( report . input ) . toBe ( message ) ;
260253} ) ;
261254
262- test ( 'returns original message with commit header and body' , async t => {
255+ test ( 'returns original message with commit header and body' , async ( ) => {
263256 const message = 'foo: bar/n/nFoo bar bizz buzz.' ;
264257 const report = await lint ( message ) ;
265258
266- t . is ( report . input , message ) ;
259+ expect ( report . input ) . toBe ( message ) ;
267260} ) ;
268261
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 ( ) => {
270263 const message = 'foo: bar/n/nFoo bar bizz buzz./n/nCloses #1' ;
271264 const report = await lint ( message ) ;
272265
273- t . is ( report . input , message ) ;
266+ expect ( report . input ) . toBe ( message ) ;
274267} ) ;
275268
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 ( ) => {
277270 const expected = 'foo: bar/n/nFoo bar bizz buzz./n/nCloses #1' ;
278271 const message = `${ expected } \n\n# Some comment to ignore` ;
279272 const report = await lint (
@@ -288,5 +281,5 @@ test('returns original message with commit header, body and footer, parsing comm
288281 }
289282 ) ;
290283
291- t . is ( report . input , expected ) ;
284+ expect ( report . input ) . toBe ( expected ) ;
292285} ) ;
0 commit comments