1- import { Rules , Level } from '@commitlint/load' ;
1+ import type { RuleConfigQuality , RulesConfig } from '@commitlint/types' ;
2+ import { RuleConfigSeverity } from '@commitlint/types' ;
23import { green , red } from 'chalk' ;
34import { validatorFactory , filterFactory , transformerFactory , bodyMaker } from './body-maker' ;
45
56describe ( 'body-maker' , ( ) => {
67 describe ( 'validatorFactory' , ( ) => {
7- test . each < [ Rules , string , string | true ] > ( [
8- [ { 'body-max-length' : [ Level . Error , 'always' , 3 ] } , 'too long' , 'Body maximum length of 3 has been exceeded' ] ,
9- [ { 'body-max-length' : [ Level . Error , 'always' , 72 ] } , 'too long' , true ] ,
10- [ { 'body-min-length' : [ Level . Error , 'always' , 3 ] } , 'f' , 'Body minimum length of 3 has not been met' ] ,
11- [ { 'body-min-length' : [ Level . Error , 'always' , 3 ] } , 'foo bar baz' , true ] ,
8+ test . each < [ Partial < RulesConfig < RuleConfigQuality . Qualified > > , string , string | true ] > ( [
9+ [
10+ { 'body-max-length' : [ RuleConfigSeverity . Error , 'always' , 3 ] } ,
11+ 'too long' ,
12+ 'Body maximum length of 3 has been exceeded' ,
13+ ] ,
14+ [ { 'body-max-length' : [ RuleConfigSeverity . Error , 'always' , 72 ] } , 'too long' , true ] ,
15+ [
16+ { 'body-min-length' : [ RuleConfigSeverity . Error , 'always' , 3 ] } ,
17+ 'f' ,
18+ 'Body minimum length of 3 has not been met' ,
19+ ] ,
20+ [ { 'body-min-length' : [ RuleConfigSeverity . Error , 'always' , 3 ] } , 'foo bar baz' , true ] ,
1221 ] ) ( `should validate rule '%o', value '%s', expected '%s'` , ( rules , value , expected ) => {
1322 const factory = validatorFactory ( rules ) ;
1423
@@ -19,9 +28,9 @@ describe('body-maker', () => {
1928 } ) ;
2029
2130 describe ( 'filterFactory' , ( ) => {
22- test . each < [ Rules , string , string ] > ( [
23- [ { 'body-leading-blank' : [ Level . Error , 'always' , undefined ] } , 'foo bar' , '\nfoo bar' ] ,
24- [ { 'body-max-line-length' : [ Level . Error , 'always' , 4 ] } , 'foo bar baz buz' , 'foo \nbar \nbaz \nbuz' ] ,
31+ test . each < [ Partial < RulesConfig < RuleConfigQuality . Qualified > > , string , string ] > ( [
32+ [ { 'body-leading-blank' : [ RuleConfigSeverity . Error , 'always' ] } , 'foo bar' , '\nfoo bar' ] ,
33+ [ { 'body-max-line-length' : [ RuleConfigSeverity . Error , 'always' , 4 ] } , 'foo bar baz buz' , 'foo \nbar \nbaz \nbuz' ] ,
2534 ] ) ( `should format rule: '%o', value: %s for expected '%s'` , ( rules , value , expected ) => {
2635 const factory = filterFactory ( rules ) ;
2736
@@ -31,9 +40,9 @@ describe('body-maker', () => {
3140 } ) ;
3241
3342 it ( 'should prepend body with and leading empty line' , ( ) => {
34- const rules : Rules = {
35- 'body-leading-blank' : [ Level . Error , 'always' , undefined ] ,
36- 'body-max-line-length' : [ Level . Error , 'never' , Infinity ] ,
43+ const rules : Partial < RulesConfig < RuleConfigQuality . Qualified > > = {
44+ 'body-leading-blank' : [ RuleConfigSeverity . Error , 'always' ] ,
45+ 'body-max-line-length' : [ RuleConfigSeverity . Error , 'never' , Infinity ] ,
3746 } ;
3847 const userTypedBody = 'my message should be prepended with an empty new line' ;
3948
@@ -44,9 +53,9 @@ describe('body-maker', () => {
4453 } ) ;
4554
4655 describe ( 'transformerFactory' , ( ) => {
47- test . each < [ Rules , string , string ] > ( [
48- [ { 'body-max-length' : [ Level . Error , 'always' , 4 ] } , 'foo' , green ( '(3) foo' ) ] ,
49- [ { 'body-max-length' : [ Level . Error , 'always' , 2 ] } , 'foo' , red ( '(3) foo' ) ] ,
56+ test . each < [ Partial < RulesConfig < RuleConfigQuality . Qualified > > , string , string ] > ( [
57+ [ { 'body-max-length' : [ RuleConfigSeverity . Error , 'always' , 4 ] } , 'foo' , green ( '(3) foo' ) ] ,
58+ [ { 'body-max-length' : [ RuleConfigSeverity . Error , 'always' , 2 ] } , 'foo' , red ( '(3) foo' ) ] ,
5059 [ { } , 'foo\\nbar' , 'foo\nbar' ] ,
5160 [ { } , 'foo' , 'foo' ] ,
5261 ] ) ( `should transform for rules: '%o', value: '%o' for expected: '%s'` , ( rules , value , expected ) => {
0 commit comments