@@ -8,12 +8,12 @@ const bin = require.resolve('../lib/cli.js');
8
8
9
9
const cli = ( args , options ) => {
10
10
return ( input = '' ) => {
11
- const c = execa ( bin , args , {
11
+ return execa ( bin , args , {
12
12
cwd : options . cwd ,
13
13
env : options . env ,
14
- input : input
14
+ input : input ,
15
+ reject : false
15
16
} ) ;
16
- return c . catch ( err => err ) ;
17
17
} ;
18
18
} ;
19
19
@@ -23,7 +23,7 @@ const fixBootstrap = fixture => fix.bootstrap(fixture, __dirname);
23
23
test ( 'should throw when called without [input]' , async ( ) => {
24
24
const cwd = await gitBootstrap ( 'fixtures/default' ) ;
25
25
const actual = await cli ( [ ] , { cwd} ) ( ) ;
26
- expect ( actual . code ) . toBe ( 1 ) ;
26
+ expect ( actual . exitCode ) . toBe ( 1 ) ;
27
27
} ) ;
28
28
29
29
test ( 'should reprint input from stdin' , async ( ) => {
@@ -57,7 +57,7 @@ test('should produce help for empty config', async () => {
57
57
const cwd = await gitBootstrap ( 'fixtures/empty' ) ;
58
58
const actual = await cli ( [ ] , { cwd} ) ( 'foo: bar' ) ;
59
59
expect ( actual . stdout ) . toContain ( 'Please add rules' ) ;
60
- expect ( actual . code ) . toBe ( 1 ) ;
60
+ expect ( actual . exitCode ) . toBe ( 1 ) ;
61
61
} ) ;
62
62
63
63
test ( 'should produce help for problems' , async ( ) => {
@@ -66,7 +66,7 @@ test('should produce help for problems', async () => {
66
66
expect ( actual . stdout ) . toContain (
67
67
'Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint'
68
68
) ;
69
- expect ( actual . code ) . toBe ( 1 ) ;
69
+ expect ( actual . exitCode ) . toBe ( 1 ) ;
70
70
} ) ;
71
71
72
72
test ( 'should produce help for problems with correct helpurl' , async ( ) => {
@@ -78,57 +78,57 @@ test('should produce help for problems with correct helpurl', async () => {
78
78
expect ( actual . stdout ) . toContain (
79
79
'Get help: https://github.com/conventional-changelog/commitlint/#testhelpurl'
80
80
) ;
81
- expect ( actual . code ) . toBe ( 1 ) ;
81
+ expect ( actual . exitCode ) . toBe ( 1 ) ;
82
82
} ) ;
83
83
84
84
test ( 'should fail for input from stdin without rules' , async ( ) => {
85
85
const cwd = await gitBootstrap ( 'fixtures/empty' ) ;
86
86
const actual = await cli ( [ ] , { cwd} ) ( 'foo: bar' ) ;
87
- expect ( actual . code ) . toBe ( 1 ) ;
87
+ expect ( actual . exitCode ) . toBe ( 1 ) ;
88
88
} ) ;
89
89
90
90
test ( 'should succeed for input from stdin with rules' , async ( ) => {
91
91
const cwd = await gitBootstrap ( 'fixtures/default' ) ;
92
92
const actual = await cli ( [ ] , { cwd} ) ( 'type: bar' ) ;
93
- expect ( actual . code ) . toBe ( 0 ) ;
93
+ expect ( actual . exitCode ) . toBe ( 0 ) ;
94
94
} ) ;
95
95
96
96
test ( 'should fail for input from stdin with rule from rc' , async ( ) => {
97
97
const cwd = await gitBootstrap ( 'fixtures/simple' ) ;
98
98
const actual = await cli ( [ ] , { cwd} ) ( 'foo: bar' ) ;
99
99
expect ( actual . stdout ) . toContain ( 'type must not be one of [foo]' ) ;
100
- expect ( actual . code ) . toBe ( 1 ) ;
100
+ expect ( actual . exitCode ) . toBe ( 1 ) ;
101
101
} ) ;
102
102
103
103
test ( 'should work with --config option' , async ( ) => {
104
104
const file = 'config/commitlint.config.js' ;
105
105
const cwd = await gitBootstrap ( 'fixtures/specify-config-file' ) ;
106
106
const actual = await cli ( [ '--config' , file ] , { cwd} ) ( 'foo: bar' ) ;
107
107
expect ( actual . stdout ) . toContain ( 'type must not be one of [foo]' ) ;
108
- expect ( actual . code ) . toBe ( 1 ) ;
108
+ expect ( actual . exitCode ) . toBe ( 1 ) ;
109
109
} ) ;
110
110
111
111
test ( 'should fail for input from stdin with rule from js' , async ( ) => {
112
112
const cwd = await gitBootstrap ( 'fixtures/extends-root' ) ;
113
113
const actual = await cli ( [ '--extends' , './extended' ] , { cwd} ) ( 'foo: bar' ) ;
114
114
expect ( actual . stdout ) . toContain ( 'type must not be one of [foo]' ) ;
115
- expect ( actual . code ) . toBe ( 1 ) ;
115
+ expect ( actual . exitCode ) . toBe ( 1 ) ;
116
116
} ) ;
117
117
118
118
test ( 'should produce no error output with --quiet flag' , async ( ) => {
119
119
const cwd = await gitBootstrap ( 'fixtures/simple' ) ;
120
120
const actual = await cli ( [ '--quiet' ] , { cwd} ) ( 'foo: bar' ) ;
121
121
expect ( actual . stdout ) . toEqual ( '' ) ;
122
122
expect ( actual . stderr ) . toEqual ( '' ) ;
123
- expect ( actual . code ) . toBe ( 1 ) ;
123
+ expect ( actual . exitCode ) . toBe ( 1 ) ;
124
124
} ) ;
125
125
126
126
test ( 'should produce no error output with -q flag' , async ( ) => {
127
127
const cwd = await gitBootstrap ( 'fixtures/simple' ) ;
128
128
const actual = await cli ( [ '-q' ] , { cwd} ) ( 'foo: bar' ) ;
129
129
expect ( actual . stdout ) . toEqual ( '' ) ;
130
130
expect ( actual . stderr ) . toEqual ( '' ) ;
131
- expect ( actual . code ) . toBe ( 1 ) ;
131
+ expect ( actual . exitCode ) . toBe ( 1 ) ;
132
132
} ) ;
133
133
134
134
test ( 'should work with husky commitmsg hook and git commit' , async ( ) => {
@@ -236,7 +236,7 @@ test('should allow reading of environment variables for edit file, succeeding if
236
236
cwd,
237
237
env : { variable : 'commit-msg-file' }
238
238
} ) ( ) ;
239
- expect ( actual . code ) . toBe ( 0 ) ;
239
+ expect ( actual . exitCode ) . toBe ( 0 ) ;
240
240
} ) ;
241
241
242
242
test ( 'should allow reading of environment variables for edit file, failing if invalid' , async ( ) => {
@@ -249,15 +249,15 @@ test('should allow reading of environment variables for edit file, failing if in
249
249
cwd,
250
250
env : { variable : 'commit-msg-file' }
251
251
} ) ( ) ;
252
- expect ( actual . code ) . toBe ( 1 ) ;
252
+ expect ( actual . exitCode ) . toBe ( 1 ) ;
253
253
} ) ;
254
254
255
255
test ( 'should pick up parser preset and fail accordingly' , async ( ) => {
256
256
const cwd = await gitBootstrap ( 'fixtures/parser-preset' ) ;
257
257
const actual = await cli ( [ '--parser-preset' , './parser-preset' ] , { cwd} ) (
258
258
'type(scope): subject'
259
259
) ;
260
- expect ( actual . code ) . toBe ( 1 ) ;
260
+ expect ( actual . exitCode ) . toBe ( 1 ) ;
261
261
expect ( actual . stdout ) . toContain ( 'may not be empty' ) ;
262
262
} ) ;
263
263
@@ -266,39 +266,39 @@ test('should pick up parser preset and succeed accordingly', async () => {
266
266
const actual = await cli ( [ '--parser-preset' , './parser-preset' ] , { cwd} ) (
267
267
'----type(scope): subject'
268
268
) ;
269
- expect ( actual . code ) . toBe ( 0 ) ;
269
+ expect ( actual . exitCode ) . toBe ( 0 ) ;
270
270
} ) ;
271
271
272
272
test ( 'should pick up config from outside git repo and fail accordingly' , async ( ) => {
273
273
const outer = await fixBootstrap ( 'fixtures/outer-scope' ) ;
274
274
const cwd = await git . init ( path . join ( outer , 'inner-scope' ) ) ;
275
275
276
276
const actual = await cli ( [ ] , { cwd} ) ( 'inner: bar' ) ;
277
- expect ( actual . code ) . toBe ( 1 ) ;
277
+ expect ( actual . exitCode ) . toBe ( 1 ) ;
278
278
} ) ;
279
279
280
280
test ( 'should pick up config from outside git repo and succeed accordingly' , async ( ) => {
281
281
const outer = await fixBootstrap ( 'fixtures/outer-scope' ) ;
282
282
const cwd = await git . init ( path . join ( outer , 'inner-scope' ) ) ;
283
283
284
284
const actual = await cli ( [ ] , { cwd} ) ( 'outer: bar' ) ;
285
- expect ( actual . code ) . toBe ( 0 ) ;
285
+ expect ( actual . exitCode ) . toBe ( 0 ) ;
286
286
} ) ;
287
287
288
288
test ( 'should pick up config from inside git repo with precedence and succeed accordingly' , async ( ) => {
289
289
const outer = await fixBootstrap ( 'fixtures/inner-scope' ) ;
290
290
const cwd = await git . init ( path . join ( outer , 'inner-scope' ) ) ;
291
291
292
292
const actual = await cli ( [ ] , { cwd} ) ( 'inner: bar' ) ;
293
- expect ( actual . code ) . toBe ( 0 ) ;
293
+ expect ( actual . exitCode ) . toBe ( 0 ) ;
294
294
} ) ;
295
295
296
296
test ( 'should pick up config from inside git repo with precedence and fail accordingly' , async ( ) => {
297
297
const outer = await fixBootstrap ( 'fixtures/inner-scope' ) ;
298
298
const cwd = await git . init ( path . join ( outer , 'inner-scope' ) ) ;
299
299
300
300
const actual = await cli ( [ ] , { cwd} ) ( 'outer: bar' ) ;
301
- expect ( actual . code ) . toBe ( 1 ) ;
301
+ expect ( actual . exitCode ) . toBe ( 1 ) ;
302
302
} ) ;
303
303
304
304
test ( 'should handle --amend with signoff' , async ( ) => {
@@ -320,7 +320,7 @@ test('should handle --amend with signoff', async () => {
320
320
test ( 'should handle linting with issue prefixes' , async ( ) => {
321
321
const cwd = await gitBootstrap ( 'fixtures/issue-prefixes' ) ;
322
322
const actual = await cli ( [ ] , { cwd} ) ( 'foobar REF-1' ) ;
323
- expect ( actual . code ) . toBe ( 0 ) ;
323
+ expect ( actual . exitCode ) . toBe ( 0 ) ;
324
324
} , 10000 ) ;
325
325
326
326
test ( 'should print full commit message when input from stdin fails' , async ( ) => {
@@ -330,7 +330,7 @@ test('should print full commit message when input from stdin fails', async () =>
330
330
const actual = await cli ( [ '--color=false' ] , { cwd} ) ( input ) ;
331
331
332
332
expect ( actual . stdout ) . toContain ( input ) ;
333
- expect ( actual . code ) . toBe ( 1 ) ;
333
+ expect ( actual . exitCode ) . toBe ( 1 ) ;
334
334
} ) ;
335
335
336
336
test ( 'should not print commit message fully or partially when input succeeds' , async ( ) => {
@@ -341,7 +341,7 @@ test('should not print commit message fully or partially when input succeeds', a
341
341
342
342
expect ( actual . stdout ) . not . toContain ( message ) ;
343
343
expect ( actual . stdout ) . not . toContain ( message . split ( '\n' ) [ 0 ] ) ;
344
- expect ( actual . code ) . toBe ( 0 ) ;
344
+ expect ( actual . exitCode ) . toBe ( 0 ) ;
345
345
} ) ;
346
346
347
347
test ( 'should fail for invalid formatters from configuration' , async ( ) => {
@@ -352,37 +352,37 @@ test('should fail for invalid formatters from configuration', async () => {
352
352
'Using format custom-formatter, but cannot find the module'
353
353
) ;
354
354
expect ( actual . stdout ) . toEqual ( '' ) ;
355
- expect ( actual . code ) . toBe ( 1 ) ;
355
+ expect ( actual . exitCode ) . toBe ( 1 ) ;
356
356
} ) ;
357
357
358
358
test ( 'should skip linting if message matches ignores config' , async ( ) => {
359
359
const cwd = await gitBootstrap ( 'fixtures/ignores' ) ;
360
360
const actual = await cli ( [ ] , { cwd} ) ( 'WIP' ) ;
361
- expect ( actual . code ) . toBe ( 0 ) ;
361
+ expect ( actual . exitCode ) . toBe ( 0 ) ;
362
362
} ) ;
363
363
364
364
test ( 'should not skip linting if message does not match ignores config' , async ( ) => {
365
365
const cwd = await gitBootstrap ( 'fixtures/ignores' ) ;
366
366
const actual = await cli ( [ ] , { cwd} ) ( 'foo' ) ;
367
- expect ( actual . code ) . toBe ( 1 ) ;
367
+ expect ( actual . exitCode ) . toBe ( 1 ) ;
368
368
} ) ;
369
369
370
370
test ( 'should not skip linting if defaultIgnores is false' , async ( ) => {
371
371
const cwd = await gitBootstrap ( 'fixtures/default-ignores-false' ) ;
372
372
const actual = await cli ( [ ] , { cwd} ) ( 'fixup! foo: bar' ) ;
373
- expect ( actual . code ) . toBe ( 1 ) ;
373
+ expect ( actual . exitCode ) . toBe ( 1 ) ;
374
374
} ) ;
375
375
376
376
test ( 'should skip linting if defaultIgnores is true' , async ( ) => {
377
377
const cwd = await gitBootstrap ( 'fixtures/default-ignores-true' ) ;
378
378
const actual = await cli ( [ ] , { cwd} ) ( 'fixup! foo: bar' ) ;
379
- expect ( actual . code ) . toBe ( 0 ) ;
379
+ expect ( actual . exitCode ) . toBe ( 0 ) ;
380
380
} ) ;
381
381
382
382
test ( 'should skip linting if defaultIgnores is unset' , async ( ) => {
383
383
const cwd = await gitBootstrap ( 'fixtures/default-ignores-unset' ) ;
384
384
const actual = await cli ( [ ] , { cwd} ) ( 'fixup! foo: bar' ) ;
385
- expect ( actual . code ) . toBe ( 0 ) ;
385
+ expect ( actual . exitCode ) . toBe ( 0 ) ;
386
386
} ) ;
387
387
388
388
test ( 'should fail for invalid formatters from flags' , async ( ) => {
@@ -393,7 +393,7 @@ test('should fail for invalid formatters from flags', async () => {
393
393
'Using format through-flag, but cannot find the module'
394
394
) ;
395
395
expect ( actual . stdout ) . toEqual ( '' ) ;
396
- expect ( actual . code ) . toBe ( 1 ) ;
396
+ expect ( actual . exitCode ) . toBe ( 1 ) ;
397
397
} ) ;
398
398
399
399
test ( 'should work with absolute formatter path' , async ( ) => {
@@ -407,7 +407,7 @@ test('should work with absolute formatter path', async () => {
407
407
) ;
408
408
409
409
expect ( actual . stdout ) . toContain ( 'custom-formatter-ok' ) ;
410
- expect ( actual . code ) . toBe ( 0 ) ;
410
+ expect ( actual . exitCode ) . toBe ( 0 ) ;
411
411
} ) ;
412
412
413
413
test ( 'should work with relative formatter path' , async ( ) => {
@@ -420,7 +420,7 @@ test('should work with relative formatter path', async () => {
420
420
) ;
421
421
422
422
expect ( actual . stdout ) . toContain ( 'custom-formatter-ok' ) ;
423
- expect ( actual . code ) . toBe ( 0 ) ;
423
+ expect ( actual . exitCode ) . toBe ( 0 ) ;
424
424
} ) ;
425
425
426
426
async function writePkg ( payload , options ) {
0 commit comments