@@ -513,7 +513,8 @@ test('should print help', async () => {
513513 Options:
514514 -c, --color toggle colored output [boolean] [default: true]
515515 -g, --config path to the config file [string]
516- --print-config print resolved config [boolean] [default: false]
516+ --print-config print resolved config
517+ [string] [choices: "", "text", "json"]
517518 -d, --cwd directory to execute in
518519 [string] [default: (Working Directory)]
519520 -e, --edit read last commit message from the specified file or
@@ -547,14 +548,16 @@ test('should print version', async () => {
547548 expect ( actual . stdout ) . toMatch ( '@commitlint/cli@' ) ;
548549} ) ;
549550
550- test ( 'should print config' , async ( ) => {
551- const cwd = await gitBootstrap ( 'fixtures/default' ) ;
552- const actual = await cli ( [ '--print-config' , '--no-color' ] , { cwd} ) ( ) ;
553- const stdout = actual . stdout
554- . replace ( / ^ { [ ^ \n ] / g, '{\n ' )
555- . replace ( / [ ^ \n ] } $ / g, '\n}' )
556- . replace ( / ( h e l p U r l : ) \n [ ] + / , '$1 ' ) ;
557- expect ( stdout ) . toMatchInlineSnapshot ( `
551+ describe ( 'should print config' , ( ) => {
552+ test ( 'should print config when flag is present but without value' , async ( ) => {
553+ const cwd = await gitBootstrap ( 'fixtures/default' ) ;
554+ const actual = await cli ( [ '--print-config' , 'text' , '--no-color' ] , { cwd} ) ( ) ;
555+
556+ const stdout = actual . stdout
557+ . replace ( / ^ { [ ^ \n ] / g, '{\n ' )
558+ . replace ( / [ ^ \n ] } $ / g, '\n}' )
559+ . replace ( / ( h e l p U r l : ) \n [ ] + / , '$1 ' ) ;
560+ expect ( stdout ) . toMatchInlineSnapshot ( `
558561 "{
559562 extends: [],
560563 formatter: '@commitlint/format',
@@ -567,6 +570,39 @@ test('should print config', async () => {
567570 prompt: {}
568571 }"
569572 ` ) ;
573+ } ) ;
574+
575+ test ( 'should print config when flag has `text` value' , async ( ) => {
576+ const cwd = await gitBootstrap ( 'fixtures/default' ) ;
577+ const actual = await cli ( [ '--print-config=text' , '--no-color' ] , { cwd} ) ( ) ;
578+
579+ const stdout = actual . stdout
580+ . replace ( / ^ { [ ^ \n ] / g, '{\n ' )
581+ . replace ( / [ ^ \n ] } $ / g, '\n}' )
582+ . replace ( / ( h e l p U r l : ) \n [ ] + / , '$1 ' ) ;
583+ expect ( stdout ) . toMatchInlineSnapshot ( `
584+ "{
585+ extends: [],
586+ formatter: '@commitlint/format',
587+ parserPreset: undefined,
588+ ignores: undefined,
589+ defaultIgnores: undefined,
590+ plugins: {},
591+ rules: { 'type-enum': [ 2, 'never', [ 'foo' ] ] },
592+ helpUrl: 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint',
593+ prompt: {}
594+ }"
595+ ` ) ;
596+ } ) ;
597+
598+ test ( 'should print config when flag has `json` value' , async ( ) => {
599+ const cwd = await gitBootstrap ( 'fixtures/default' ) ;
600+ const actual = await cli ( [ '--print-config=json' , '--no-color' ] , { cwd} ) ( ) ;
601+
602+ expect ( actual . stdout ) . toMatchInlineSnapshot (
603+ `"{"extends":[],"formatter":"@commitlint/format","plugins":{},"rules":{"type-enum":[2,"never",["foo"]]},"helpUrl":"https://github.com/conventional-changelog/commitlint/#what-is-commitlint\","prompt":{}}"`
604+ ) ;
605+ } ) ;
570606} ) ;
571607
572608async function writePkg ( payload : unknown , options : TestOptions ) {
0 commit comments