@@ -4,9 +4,14 @@ import execa from 'execa';
4
4
import merge from 'lodash/merge' ;
5
5
import fs from 'fs-extra' ;
6
6
7
- const bin = require . resolve ( '../lib/ cli.js' ) ;
7
+ const bin = require . resolve ( '../cli.js' ) ;
8
8
9
- const cli = ( args , options ) => {
9
+ interface TestOptions {
10
+ cwd : string ;
11
+ env ?: Record < string , string > ;
12
+ }
13
+
14
+ const cli = ( args : string [ ] , options : TestOptions ) => {
10
15
return ( input = '' ) => {
11
16
return execa ( bin , args , {
12
17
cwd : options . cwd ,
@@ -17,8 +22,8 @@ const cli = (args, options) => {
17
22
} ;
18
23
} ;
19
24
20
- const gitBootstrap = fixture => git . bootstrap ( fixture , __dirname ) ;
21
- const fixBootstrap = fixture => fix . bootstrap ( fixture , __dirname ) ;
25
+ const gitBootstrap = ( fixture : string ) => git . bootstrap ( fixture , __dirname ) ;
26
+ const fixBootstrap = ( fixture : string ) => fix . bootstrap ( fixture , __dirname ) ;
22
27
23
28
test ( 'should throw when called without [input]' , async ( ) => {
24
29
const cwd = await gitBootstrap ( 'fixtures/default' ) ;
@@ -423,7 +428,48 @@ test('should work with relative formatter path', async () => {
423
428
expect ( actual . exitCode ) . toBe ( 0 ) ;
424
429
} ) ;
425
430
426
- async function writePkg ( payload , options ) {
431
+ test ( 'should print help' , async ( ) => {
432
+ const cwd = await gitBootstrap ( 'fixtures/default' ) ;
433
+ const actual = await cli ( [ '--help' ] , { cwd} ) ( ) ;
434
+ expect ( actual . stdout ) . toMatchInlineSnapshot ( `
435
+ "@commitlint/[email protected] - Lint your commit messages
436
+
437
+ [input] reads from stdin if --edit, --env, --from and --to are omitted
438
+
439
+ Options:
440
+ --color, -c toggle colored output [boolean] [default: true]
441
+ --config, -g path to the config file [string]
442
+ --cwd, -d directory to execute in
443
+ [string] [default: (Working Directory)]
444
+ --edit, -e read last commit message from the specified file or
445
+ fallbacks to ./.git/COMMIT_EDITMSG
446
+ [string] [default: false]
447
+ --env, -E check message in the file at path given by environment
448
+ variable value [string]
449
+ --extends, -x array of shareable configurations to extend [array]
450
+ --help-url, -H help url in error message [string]
451
+ --from, -f lower end of the commit range to lint; applies if
452
+ edit=false [string]
453
+ --format, -o output format of the results [string]
454
+ --parser-preset, -p configuration preset to use for
455
+ conventional-commits-parser [string]
456
+ --quiet, -q toggle console output [boolean] [default: false]
457
+ --to, -t upper end of the commit range to lint; applies if
458
+ edit=false [string]
459
+ --verbose, -V enable verbose output for reports without problems
460
+ [boolean]
461
+ -v, --version display version information [boolean]
462
+ -h, --help Show help [boolean]"
463
+ ` ) ;
464
+ } ) ;
465
+
466
+ test ( 'should print version' , async ( ) => {
467
+ const cwd = await gitBootstrap ( 'fixtures/default' ) ;
468
+ const actual = await cli ( [ '--version' ] , { cwd} ) ( ) ;
469
+ expect ( actual . stdout ) . toMatch ( '@commitlint/cli@' ) ;
470
+ } ) ;
471
+
472
+ async function writePkg ( payload : unknown , options : TestOptions ) {
427
473
const pkgPath = path . join ( options . cwd , 'package.json' ) ;
428
474
const pkg = JSON . parse ( await fs . readFile ( pkgPath , 'utf-8' ) ) ;
429
475
const result = merge ( pkg , payload ) ;
0 commit comments