11import { ListQuestion } from 'inquirer' ;
22import { Rule , Case , Level , Rules } from '@commitlint/load' ;
3- import { scopeMaker , filterFactory , validatorFactory } from './scope-maker' ;
3+ import { scopeMaker , filterFactory , validatorFactory , choicesFactory } from './scope-maker' ;
44
55describe ( 'scopeMaker' , ( ) => {
66 describe ( 'validatorFactory' , ( ) => {
@@ -54,7 +54,7 @@ describe('scopeMaker', () => {
5454 } ) ;
5555
5656 describe ( 'choices' , ( ) => {
57- test ( 'should display choices if array scope enum is present' , ( ) => {
57+ it ( 'should display choices if array scope enum is present' , ( ) => {
5858 const scopeConfig = scopeMaker ( [ ] , { 'scope-enum' : [ 2 , 'always' , [ 'foo' , 'bar' ] ] } ) [ 0 ] as ListQuestion ;
5959
6060 if ( scopeConfig . choices ) {
@@ -76,6 +76,38 @@ describe('scopeMaker', () => {
7676 } ) ;
7777 } ) ;
7878
79+ describe ( 'choicesFactory' , ( ) => {
80+ it ( 'should not allow non-empty scope when empty scope is required' , ( ) => {
81+ const scopeConfig = choicesFactory ( {
82+ 'scope-empty' : [ 2 , 'always' , undefined ]
83+ } ) ;
84+
85+ expect ( scopeConfig ) . toEqual ( [ { name : ':skip' , value : '' } ] ) ;
86+ } ) ;
87+
88+ it ( 'should not allow skipping scope when is required' , ( ) => {
89+ const scopeConfig = choicesFactory ( {
90+ 'scope-empty' : [ 2 , 'never' , undefined ]
91+ } ) ;
92+
93+ expect ( scopeConfig ) . not . toContainEqual ( { name : ':skip' , value : '' } ) ;
94+ } ) ;
95+ } ) ;
96+
97+ it ( 'should allow skipping scope when "scope-empty" severity is "warn"' , ( ) => {
98+ const scopeConfig = choicesFactory ( {
99+ 'scope-empty' : [ 1 , 'always' , undefined ]
100+ } ) ;
101+
102+ expect ( scopeConfig ) . toContainEqual ( { name : ':skip' , value : '' } ) ;
103+ } ) ;
104+
105+ it ( 'should allow skipping scope when "scope-empty" rule is not set' , ( ) => {
106+ const scopeConfig = choicesFactory ( { } ) ;
107+
108+ expect ( scopeConfig ) . toContainEqual ( { name : ':skip' , value : '' } ) ;
109+ } ) ;
110+
79111 describe ( 'filterFactory' , ( ) => {
80112 test . each < [ Rule < Case > , string , string ] > ( [
81113 [ [ Level . Error , 'always' , 'camel-case' ] , 'FOO_BAR' , 'fooBar' ] ,
0 commit comments