1- import { Level , Rules } from '@commitlint/load' ;
1+ import type { RuleConfigQuality , RulesConfig } from '@commitlint/types' ;
2+ import { RuleConfigSeverity } from '@commitlint/types' ;
23import { types } from 'conventional-commit-types' ;
34
45import { filterFactory , choicesFactory , validatorFactory , typeMaker } from './type-maker' ;
@@ -7,17 +8,25 @@ jest.mock('conventional-commit-types');
78
89describe ( 'type-maker' , ( ) => {
910 describe ( 'validatorFactory' , ( ) => {
10- test . each < [ Rules , string , string | true ] > ( [
11- [ { 'type-empty' : [ Level . Error , 'never' , undefined ] } , '' , 'Type cannot be empty' ] ,
12- [ { 'type-empty' : [ Level . Error , 'never' , undefined ] } , 'foo' , true ] ,
13- [ { 'type-max-length' : [ Level . Error , 'always' , 3 ] } , 'too long' , 'Type maximum length of 3 has been exceeded' ] ,
14- [ { 'type-max-length' : [ Level . Error , 'always' , 72 ] } , 'too long' , true ] ,
15- [ { 'type-min-length' : [ Level . Error , 'always' , 3 ] } , 'f' , 'Type minimum length of 3 has not been met' ] ,
16- [ { 'type-min-length' : [ Level . Error , 'always' , 3 ] } , 'foo bar baz' , true ] ,
17- [ { 'type-case' : [ Level . Error , 'never' , 'upper-case' ] } , 'FOO_BAR' , 'Type must not be in upper-case' ] ,
18- [ { 'type-case' : [ Level . Error , 'never' , 'upper-case' ] } , 'foo bar' , true ] ,
19- [ { 'type-case' : [ Level . Error , 'always' , 'upper-case' ] } , 'FOO_BAR' , true ] ,
20- [ { 'type-case' : [ Level . Error , 'always' , 'upper-case' ] } , 'foo bar' , 'Type must be in upper-case' ] ,
11+ test . each < [ Partial < RulesConfig < RuleConfigQuality . Qualified > > , string , string | true ] > ( [
12+ [ { 'type-empty' : [ RuleConfigSeverity . Error , 'never' ] } , '' , 'Type cannot be empty' ] ,
13+ [ { 'type-empty' : [ RuleConfigSeverity . Error , 'never' ] } , 'foo' , true ] ,
14+ [
15+ { 'type-max-length' : [ RuleConfigSeverity . Error , 'always' , 3 ] } ,
16+ 'too long' ,
17+ 'Type maximum length of 3 has been exceeded' ,
18+ ] ,
19+ [ { 'type-max-length' : [ RuleConfigSeverity . Error , 'always' , 72 ] } , 'too long' , true ] ,
20+ [
21+ { 'type-min-length' : [ RuleConfigSeverity . Error , 'always' , 3 ] } ,
22+ 'f' ,
23+ 'Type minimum length of 3 has not been met' ,
24+ ] ,
25+ [ { 'type-min-length' : [ RuleConfigSeverity . Error , 'always' , 3 ] } , 'foo bar baz' , true ] ,
26+ [ { 'type-case' : [ RuleConfigSeverity . Error , 'never' , 'upper-case' ] } , 'FOO_BAR' , 'Type must not be in upper-case' ] ,
27+ [ { 'type-case' : [ RuleConfigSeverity . Error , 'never' , 'upper-case' ] } , 'foo bar' , true ] ,
28+ [ { 'type-case' : [ RuleConfigSeverity . Error , 'always' , 'upper-case' ] } , 'FOO_BAR' , true ] ,
29+ [ { 'type-case' : [ RuleConfigSeverity . Error , 'always' , 'upper-case' ] } , 'foo bar' , 'Type must be in upper-case' ] ,
2130 ] ) ( `should validate rule '%o', value '%s', expected '%s'` , ( rules , value , expected ) => {
2231 const factory = validatorFactory ( rules ) ;
2332
@@ -29,7 +38,7 @@ describe('type-maker', () => {
2938
3039 describe ( 'filterFactory' , ( ) => {
3140 test ( 'should return filter that applies given type-case rule' , ( ) => {
32- const factory = filterFactory ( { 'type-case' : [ Level . Error , 'always' , 'camel-case' ] } ) ;
41+ const factory = filterFactory ( { 'type-case' : [ RuleConfigSeverity . Error , 'always' , 'camel-case' ] } ) ;
3342
3443 const result = factory ( 'FOO_BAR' ) ;
3544
@@ -104,7 +113,7 @@ describe('type-maker', () => {
104113 } ) ;
105114
106115 describe ( 'should return choices if type-enum exits' , ( ) => {
107- const result = choicesFactory ( { 'type-enum' : [ Level . Error , 'always' , [ 'foo' , 'bar' , 'baz' ] ] } , { } ) ;
116+ const result = choicesFactory ( { 'type-enum' : [ RuleConfigSeverity . Error , 'always' , [ 'foo' , 'bar' , 'baz' ] ] } , { } ) ;
108117
109118 expect ( result ) . toEqual ( [
110119 {
@@ -126,7 +135,7 @@ describe('type-maker', () => {
126135
127136 describe ( 'should return choices with conventional-conmmit-types descriptions' , ( ) => {
128137 const result = choicesFactory (
129- { 'type-enum' : [ Level . Error , 'always' , [ 'foo' , 'bar' , 'baz' ] ] } ,
138+ { 'type-enum' : [ RuleConfigSeverity . Error , 'always' , [ 'foo' , 'bar' , 'baz' ] ] } ,
130139 {
131140 foo : { description : 'Fooey' , title : '' } ,
132141 bar : { description : 'Barey' , title : '' } ,
@@ -155,7 +164,7 @@ describe('type-maker', () => {
155164
156165 describe ( 'should pad the name to match the longest' , ( ) => {
157166 const result = choicesFactory (
158- { 'type-enum' : [ Level . Error , 'always' , [ 'foo' , 'bar' , 'baz' , 'very-long' ] ] } ,
167+ { 'type-enum' : [ RuleConfigSeverity . Error , 'always' , [ 'foo' , 'bar' , 'baz' , 'very-long' ] ] } ,
159168 {
160169 foo : { description : 'Fooey' , title : '' } ,
161170 bar : { description : 'Barey' , title : '' } ,
0 commit comments