1
1
import importFrom from 'import-from' ;
2
- import test from 'ava' ;
3
2
import parse from '.' ;
4
3
5
- test ( 'throws when called without params' , async t => {
6
- const error = await t . throws ( parse ( ) ) ;
7
- t . is ( error . message , 'Expected a raw commit' ) ;
4
+ test ( 'throws when called without params' , ( ) => {
5
+ expect ( ( parse as any ) ( ) ) . rejects . toThrowError ( 'Expected a raw commit' ) ;
8
6
} ) ;
9
7
10
- test ( 'throws when called with empty message' , async t => {
11
- const error = await t . throws ( parse ( ) ) ;
12
- t . is ( error . message , 'Expected a raw commit' ) ;
8
+ test ( 'throws when called with empty message' , ( ) => {
9
+ expect ( parse ( '' ) ) . rejects . toThrowError ( 'Expected a raw commit' ) ;
13
10
} ) ;
14
11
15
- test ( 'returns object with raw message' , async t => {
12
+ test ( 'returns object with raw message' , async ( ) => {
16
13
const message = 'type(scope): subject' ;
17
14
const actual = await parse ( message ) ;
18
- t . is ( actual . raw , message ) ;
15
+
16
+ expect ( actual ) . toHaveProperty ( 'raw' , message ) ;
19
17
} ) ;
20
18
21
- test ( 'calls parser with message and passed options' , async t => {
19
+ test ( 'calls parser with message and passed options' , async ( ) => {
22
20
const message = 'message' ;
23
21
24
- await parse ( message , m => {
25
- t . is ( message , m ) ;
26
- return { } ;
27
- } ) ;
22
+ expect . assertions ( 1 ) ;
23
+ await parse (
24
+ message ,
25
+ ( m : string ) : any => {
26
+ expect ( m ) . toBe ( message ) ;
27
+ return { } ;
28
+ }
29
+ ) ;
28
30
} ) ;
29
31
30
- test ( 'passes object up from parser function' , async t => {
32
+ test ( 'passes object up from parser function' , async ( ) => {
31
33
const message = 'message' ;
32
- const result = { } ;
34
+ const result : any = { } ;
33
35
const actual = await parse ( message , ( ) => result ) ;
34
- t . is ( actual , result ) ;
36
+
37
+ expect ( actual ) . toBe ( result ) ;
35
38
} ) ;
36
39
37
- test ( 'returns object with expected keys' , async t => {
40
+ test ( 'returns object with expected keys' , async ( ) => {
38
41
const message = 'message' ;
39
42
const actual = await parse ( message ) ;
40
43
const expected = {
@@ -51,10 +54,11 @@ test('returns object with expected keys', async t => {
51
54
subject : null ,
52
55
type : null
53
56
} ;
54
- t . deepEqual ( actual , expected ) ;
57
+
58
+ expect ( actual ) . toMatchObject ( expected ) ;
55
59
} ) ;
56
60
57
- test ( 'uses angular grammar' , async t => {
61
+ test ( 'uses angular grammar' , async ( ) => {
58
62
const message = 'type(scope): subject' ;
59
63
const actual = await parse ( message ) ;
60
64
const expected = {
@@ -71,14 +75,15 @@ test('uses angular grammar', async t => {
71
75
subject : 'subject' ,
72
76
type : 'type'
73
77
} ;
74
- t . deepEqual ( actual , expected ) ;
78
+
79
+ expect ( actual ) . toMatchObject ( expected ) ;
75
80
} ) ;
76
81
77
- test ( 'uses custom opts parser' , async t => {
82
+ test ( 'uses custom opts parser' , async ( ) => {
78
83
const message = 'type(scope)-subject' ;
79
- const changelogOpts = await importFrom (
80
- process . cwd ( ) ,
81
- './fixtures/parser-preset/conventional-changelog-custom'
84
+ const changelogOpts : any = await importFrom (
85
+ __dirname ,
86
+ '.. /fixtures/parser-preset/conventional-changelog-custom.js '
82
87
) ;
83
88
const actual = await parse ( message , undefined , changelogOpts . parserOpts ) ;
84
89
const expected = {
@@ -95,10 +100,11 @@ test('uses custom opts parser', async t => {
95
100
subject : 'subject' ,
96
101
type : 'type'
97
102
} ;
98
- t . deepEqual ( actual , expected ) ;
103
+
104
+ expect ( actual ) . toMatchObject ( expected ) ;
99
105
} ) ;
100
106
101
- test ( 'does not merge array properties with custom opts' , async t => {
107
+ test ( 'does not merge array properties with custom opts' , async ( ) => {
102
108
const message = 'type: subject' ;
103
109
const actual = await parse ( message , undefined , {
104
110
headerPattern : / ^ ( .* ) : \s ( .* ) $ / ,
@@ -117,73 +123,79 @@ test('does not merge array properties with custom opts', async t => {
117
123
subject : 'subject' ,
118
124
type : 'type'
119
125
} ;
120
- t . deepEqual ( actual , expected ) ;
126
+
127
+ expect ( actual ) . toMatchObject ( expected ) ;
121
128
} ) ;
122
129
123
- test ( 'supports scopes with /' , async t => {
130
+ test ( 'supports scopes with /' , async ( ) => {
124
131
const message = 'type(some/scope): subject' ;
125
132
const actual = await parse ( message ) ;
126
- t . is ( actual . scope , 'some/scope' ) ;
127
- t . is ( actual . subject , 'subject' ) ;
133
+
134
+ expect ( actual . scope ) . toBe ( 'some/scope' ) ;
135
+ expect ( actual . subject ) . toBe ( 'subject' ) ;
128
136
} ) ;
129
137
130
- test ( 'supports scopes with / and empty parserOpts' , async t => {
138
+ test ( 'supports scopes with / and empty parserOpts' , async ( ) => {
131
139
const message = 'type(some/scope): subject' ;
132
140
const actual = await parse ( message , undefined , { } ) ;
133
- t . is ( actual . scope , 'some/scope' ) ;
134
- t . is ( actual . subject , 'subject' ) ;
141
+
142
+ expect ( actual . scope ) . toBe ( 'some/scope' ) ;
143
+ expect ( actual . subject ) . toBe ( 'subject' ) ;
135
144
} ) ;
136
145
137
- test ( 'ignores comments' , async t => {
146
+ test ( 'ignores comments' , async ( ) => {
138
147
const message = 'type(some/scope): subject\n# some comment' ;
139
- const changelogOpts = await importFrom (
148
+ const changelogOpts : any = await importFrom (
140
149
process . cwd ( ) ,
141
150
'conventional-changelog-angular'
142
151
) ;
143
152
const opts = Object . assign ( { } , changelogOpts . parserOpts , {
144
153
commentChar : '#'
145
154
} ) ;
146
155
const actual = await parse ( message , undefined , opts ) ;
147
- t . is ( actual . body , null ) ;
148
- t . is ( actual . footer , null ) ;
149
- t . is ( actual . subject , 'subject' ) ;
156
+
157
+ expect ( actual . body ) . toBe ( null ) ;
158
+ expect ( actual . footer ) . toBe ( null ) ;
159
+ expect ( actual . subject ) . toBe ( 'subject' ) ;
150
160
} ) ;
151
161
152
- test ( 'registers inline #' , async t => {
162
+ test ( 'registers inline #' , async ( ) => {
153
163
const message =
154
164
'type(some/scope): subject #reference\n# some comment\nthings #reference' ;
155
- const changelogOpts = await importFrom (
165
+ const changelogOpts : any = await importFrom (
156
166
process . cwd ( ) ,
157
167
'conventional-changelog-angular'
158
168
) ;
159
169
const opts = Object . assign ( { } , changelogOpts . parserOpts , {
160
170
commentChar : '#'
161
171
} ) ;
162
172
const actual = await parse ( message , undefined , opts ) ;
163
- t . is ( actual . subject , 'subject #reference' ) ;
164
- t . is ( actual . body , 'things #reference' ) ;
173
+
174
+ expect ( actual . subject ) . toBe ( 'subject #reference' ) ;
175
+ expect ( actual . body ) . toBe ( 'things #reference' ) ;
165
176
} ) ;
166
177
167
- test ( 'parses references leading subject' , async t => {
178
+ test ( 'parses references leading subject' , async ( ) => {
168
179
const message = '#1 some subject' ;
169
180
const opts = await importFrom (
170
181
process . cwd ( ) ,
171
182
'conventional-changelog-angular'
172
183
) ;
173
184
const {
174
185
references : [ actual ]
175
- } = await parse ( message , undefined , opts ) ;
176
- t . is ( actual . issue , '1' ) ;
186
+ } = await parse ( message , undefined , opts as any ) ;
187
+
188
+ expect ( actual . issue ) . toBe ( '1' ) ;
177
189
} ) ;
178
190
179
- test ( 'parses custom references' , async t => {
191
+ test ( 'parses custom references' , async ( ) => {
180
192
const message = '#1 some subject PREFIX-2' ;
181
193
const { references} = await parse ( message , undefined , {
182
194
issuePrefixes : [ 'PREFIX-' ]
183
195
} ) ;
184
196
185
- t . falsy ( references . find ( ref => ref . issue === '1' ) ) ;
186
- t . deepEqual ( references . find ( ref => ref . issue === '2' ) , {
197
+ expect ( references . find ( ref => ref . issue === '1' ) ) . toBeFalsy ( ) ;
198
+ expect ( references . find ( ref => ref . issue === '2' ) ) . toMatchObject ( {
187
199
action : null ,
188
200
issue : '2' ,
189
201
owner : null ,
@@ -193,44 +205,44 @@ test('parses custom references', async t => {
193
205
} ) ;
194
206
} ) ;
195
207
196
- test ( 'uses permissive default regex without parser opts' , async t => {
208
+ test ( 'uses permissive default regex without parser opts' , async ( ) => {
197
209
const message = 'chore(component,demo): bump' ;
198
210
const actual = await parse ( message ) ;
199
211
200
- t . is ( actual . scope , 'component,demo' ) ;
212
+ expect ( actual . scope ) . toBe ( 'component,demo' ) ;
201
213
} ) ;
202
214
203
- test ( 'uses permissive default regex with other parser opts' , async t => {
215
+ test ( 'uses permissive default regex with other parser opts' , async ( ) => {
204
216
const message = 'chore(component,demo): bump' ;
205
217
const actual = await parse ( message , undefined , { commentChar : '#' } ) ;
206
218
207
- t . is ( actual . scope , 'component,demo' ) ;
219
+ expect ( actual . scope ) . toBe ( 'component,demo' ) ;
208
220
} ) ;
209
221
210
- test ( 'uses restrictive default regex in passed parser opts' , async t => {
222
+ test ( 'uses restrictive default regex in passed parser opts' , async ( ) => {
211
223
const message = 'chore(component,demo): bump' ;
212
224
const actual = await parse ( message , undefined , {
213
225
headerPattern : / ^ ( \w * ) (?: \( ( [ a - z ] * ) \) ) ? : ( .* ) $ /
214
226
} ) ;
215
227
216
- t . is ( actual . subject , null ) ;
217
- t . is ( actual . scope , null ) ;
228
+ expect ( actual . subject ) . toBe ( null ) ;
229
+ expect ( actual . scope ) . toBe ( null ) ;
218
230
} ) ;
219
231
220
- test ( 'works with chinese scope by default' , async t => {
232
+ test ( 'works with chinese scope by default' , async ( ) => {
221
233
const message = 'fix(面试评价): 测试' ;
222
234
const actual = await parse ( message , undefined , { commentChar : '#' } ) ;
223
235
224
- t . not ( actual . subject , null ) ;
225
- t . not ( actual . scope , null ) ;
236
+ expect ( actual . subject ) . not . toBe ( null ) ;
237
+ expect ( actual . scope ) . not . toBe ( null ) ;
226
238
} ) ;
227
239
228
- test ( 'does not work with chinese scopes with incompatible pattern' , async t => {
240
+ test ( 'does not work with chinese scopes with incompatible pattern' , async ( ) => {
229
241
const message = 'fix(面试评价): 测试' ;
230
242
const actual = await parse ( message , undefined , {
231
243
headerPattern : / ^ ( \w * ) (?: \( ( [ a - z ] * ) \) ) ? : ( .* ) $ /
232
244
} ) ;
233
245
234
- t . is ( actual . subject , null ) ;
235
- t . is ( actual . scope , null ) ;
246
+ expect ( actual . subject ) . toBe ( null ) ;
247
+ expect ( actual . scope ) . toBe ( null ) ;
236
248
} ) ;
0 commit comments