1- import { Rules , Level } from '@commitlint/load ' ;
2-
1+ import type { RuleConfigQuality , RulesConfig } from '@commitlint/types ' ;
2+ import { RuleConfigSeverity } from '@commitlint/types' ;
33import { green , red } from 'chalk' ;
44import { Answers } from '../commit-template' ;
55import { validatorFactory , filterFactory , messageFactory , transformerFactory , subjectMaker } from './subject-maker' ;
66
77describe ( 'subject-maker' , ( ) => {
88 describe ( 'validatorFactory' , ( ) => {
9- test . each < [ Rules , string , Answers , string | true ] > ( [
9+ test . each < [ Partial < RulesConfig < RuleConfigQuality . Qualified > > , string , Answers , string | true ] > ( [
1010 [
11- { 'header-max-length' : [ Level . Error , 'always' , 3 ] } ,
11+ { 'header-max-length' : [ RuleConfigSeverity . Error , 'always' , 3 ] } ,
1212 'too long' ,
1313 { type : 'feat' } ,
1414 'Header "feat: too long" cannot be longer than 3' ,
1515 ] ,
16- [ { 'header-max-length' : [ Level . Error , 'always' , 72 ] } , 'too long' , { type : 'feat' } , true ] ,
17- [ { 'subject-empty' : [ Level . Error , 'never' , undefined ] } , '' , { } , 'Subject cannot be empty' ] ,
18- [ { 'subject-empty' : [ Level . Error , 'never' , undefined ] } , 'foo' , { } , true ] ,
16+ [ { 'header-max-length' : [ RuleConfigSeverity . Error , 'always' , 72 ] } , 'too long' , { type : 'feat' } , true ] ,
17+ [ { 'subject-empty' : [ RuleConfigSeverity . Error , 'never' ] } , '' , { } , 'Subject cannot be empty' ] ,
18+ [ { 'subject-empty' : [ RuleConfigSeverity . Error , 'never' ] } , 'foo' , { } , true ] ,
1919 [
20- { 'subject-max-length' : [ Level . Error , 'always' , 3 ] } ,
20+ { 'subject-max-length' : [ RuleConfigSeverity . Error , 'always' , 3 ] } ,
2121 'too long' ,
2222 { } ,
2323 'Subject maximum length of 3 has been exceeded' ,
2424 ] ,
25- [ { 'subject-max-length' : [ Level . Error , 'always' , 72 ] } , 'too long' , { } , true ] ,
26- [ { 'subject-min-length' : [ Level . Error , 'always' , 3 ] } , 'f' , { } , 'Subject minimum length of 3 has not been met' ] ,
27- [ { 'subject-min-length' : [ Level . Error , 'always' , 3 ] } , 'foo bar baz' , { } , true ] ,
28- [ { 'subject-case' : [ Level . Error , 'never' , 'upper-case' ] } , 'FOO_BAR' , { } , 'Subject must not be in upper-case' ] ,
29- [ { 'subject-case' : [ Level . Error , 'never' , 'upper-case' ] } , 'foo bar' , { } , true ] ,
30- [ { 'subject-case' : [ Level . Error , 'always' , 'upper-case' ] } , 'FOO_BAR' , { } , true ] ,
31- [ { 'subject-case' : [ Level . Error , 'always' , 'upper-case' ] } , 'foo bar' , { } , 'Subject must be in upper-case' ] ,
25+ [ { 'subject-max-length' : [ RuleConfigSeverity . Error , 'always' , 72 ] } , 'too long' , { } , true ] ,
26+ [
27+ { 'subject-min-length' : [ RuleConfigSeverity . Error , 'always' , 3 ] } ,
28+ 'f' ,
29+ { } ,
30+ 'Subject minimum length of 3 has not been met' ,
31+ ] ,
32+ [ { 'subject-min-length' : [ RuleConfigSeverity . Error , 'always' , 3 ] } , 'foo bar baz' , { } , true ] ,
33+ [
34+ { 'subject-case' : [ RuleConfigSeverity . Error , 'never' , 'upper-case' ] } ,
35+ 'FOO_BAR' ,
36+ { } ,
37+ 'Subject must not be in upper-case' ,
38+ ] ,
39+ [ { 'subject-case' : [ RuleConfigSeverity . Error , 'never' , 'upper-case' ] } , 'foo bar' , { } , true ] ,
40+ [ { 'subject-case' : [ RuleConfigSeverity . Error , 'always' , 'upper-case' ] } , 'FOO_BAR' , { } , true ] ,
41+ [
42+ { 'subject-case' : [ RuleConfigSeverity . Error , 'always' , 'upper-case' ] } ,
43+ 'foo bar' ,
44+ { } ,
45+ 'Subject must be in upper-case' ,
46+ ] ,
3247 ] ) ( `should validate rule '%o', value '%s', answers: %o as expected '%s'` , ( rules , value , answers , expected ) => {
3348 const factory = validatorFactory ( rules ) ;
3449
@@ -39,9 +54,9 @@ describe('subject-maker', () => {
3954 } ) ;
4055
4156 describe ( 'fiterFactory' , ( ) => {
42- test . each < [ Rules , string , string ] > ( [
43- [ { 'subject-case' : [ Level . Error , 'always' , 'camel-case' ] } , 'FOO_BAR' , 'fooBar' ] ,
44- [ { 'subject-full-stop' : [ Level . Error , 'never' , '.' ] } , 'foo bar.' , 'foo bar' ] ,
57+ test . each < [ Partial < RulesConfig < RuleConfigQuality . Qualified > > , string , string ] > ( [
58+ [ { 'subject-case' : [ RuleConfigSeverity . Error , 'always' , 'camel-case' ] } , 'FOO_BAR' , 'fooBar' ] ,
59+ [ { 'subject-full-stop' : [ RuleConfigSeverity . Error , 'never' , '.' ] } , 'foo bar.' , 'foo bar' ] ,
4560 ] ) ( `should format rule: '%o', value: %s for expected '%s'` , ( rules , value , expected ) => {
4661 const factory = filterFactory ( rules ) ;
4762
@@ -52,9 +67,9 @@ describe('subject-maker', () => {
5267 } ) ;
5368
5469 describe ( 'messageFactory' , ( ) => {
55- test . each < [ Rules , Answers , string ] > ( [
70+ test . each < [ Partial < RulesConfig < RuleConfigQuality . Qualified > > , Answers , string ] > ( [
5671 [
57- { 'header-max-length' : [ Level . Error , 'always' , 72 ] } ,
72+ { 'header-max-length' : [ RuleConfigSeverity . Error , 'always' , 72 ] } ,
5873 { type : 'feat' , scope : 'foo' } ,
5974 'Write a short, imperative tense description of the change (max 61 chars):\n' ,
6075 ] ,
@@ -69,11 +84,21 @@ describe('subject-maker', () => {
6984 } ) ;
7085
7186 describe ( 'transformerFactory' , ( ) => {
72- test . each < [ Rules , string , Answers , string ] > ( [
73- [ { 'header-max-length' : [ Level . Error , 'always' , 14 ] } , 'foo' , { type : 'feat' , scope : 'bar' } , green ( '(3) foo' ) ] ,
74- [ { 'header-max-length' : [ Level . Error , 'always' , 13 ] } , 'foo' , { type : 'feat' , scope : 'bar' } , red ( '(3) foo' ) ] ,
75- [ { 'subject-max-length' : [ Level . Error , 'always' , 3 ] } , 'foo' , { } , green ( '(3) foo' ) ] ,
76- [ { 'subject-max-length' : [ Level . Error , 'always' , 2 ] } , 'foo' , { } , red ( '(3) foo' ) ] ,
87+ test . each < [ Partial < RulesConfig < RuleConfigQuality . Qualified > > , string , Answers , string ] > ( [
88+ [
89+ { 'header-max-length' : [ RuleConfigSeverity . Error , 'always' , 14 ] } ,
90+ 'foo' ,
91+ { type : 'feat' , scope : 'bar' } ,
92+ green ( '(3) foo' ) ,
93+ ] ,
94+ [
95+ { 'header-max-length' : [ RuleConfigSeverity . Error , 'always' , 13 ] } ,
96+ 'foo' ,
97+ { type : 'feat' , scope : 'bar' } ,
98+ red ( '(3) foo' ) ,
99+ ] ,
100+ [ { 'subject-max-length' : [ RuleConfigSeverity . Error , 'always' , 3 ] } , 'foo' , { } , green ( '(3) foo' ) ] ,
101+ [ { 'subject-max-length' : [ RuleConfigSeverity . Error , 'always' , 2 ] } , 'foo' , { } , red ( '(3) foo' ) ] ,
77102 [ { } , 'foo' , { } , 'foo' ] ,
78103 ] ) (
79104 `should transform for rules: '%o', value: '%o', answers: '%o' for expected: '%s'` ,
0 commit comments