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