11import { test , expect } from "vitest" ;
22import parse from "@commitlint/parse" ;
3+ import type { Commit } from "conventional-commits-parser" ;
34import { bodyMaxLineLength } from "./body-max-line-length.js" ;
45
56const short = "a" ;
67const long = "ab" ;
8+ const url = "https://example.com/URL/with/a/very/long/path" ;
79
810const value = short . length ;
911
@@ -13,14 +15,30 @@ const messages = {
1315 long : `test: subject\n${ long } ` ,
1416 shortMultipleLines : `test:subject\n${ short } \n${ short } \n${ short } ` ,
1517 longMultipleLines : `test:subject\n${ short } \n${ long } \n${ short } ` ,
16- } ;
18+ urlStandalone : `test:subject\n${ short } \n${ url } \n${ short } ` ,
19+ urlMarkdownLinkInline : `test:subject
20+
21+ This is a [link](${ url } ).` ,
22+ urlMarkdownLinkInList : `test:subject
23+
24+ Link in a list:
25+
26+ - ${ url } ` ,
27+ urlMarkdownLinkInFooter : `test:subject
1728
18- const parsed = {
19- empty : parse ( messages . empty ) ,
20- short : parse ( messages . short ) ,
21- long : parse ( messages . long ) ,
29+ Finally, [link][] via footer.
30+
31+ [link]: ${ url } ` ,
2232} ;
2333
34+ const parsed = Object . entries ( messages ) . reduce (
35+ ( _parsed , [ key , message ] ) =>
36+ Object . assign ( _parsed , {
37+ [ key ] : parse ( message ) ,
38+ } ) ,
39+ { } as Record < keyof typeof messages , Promise < Commit > > ,
40+ ) ;
41+
2442test ( "with empty should succeed" , async ( ) => {
2543 const [ actual ] = bodyMaxLineLength ( await parsed . empty , undefined , value ) ;
2644 const expected = true ;
@@ -40,13 +58,41 @@ test("with long should fail", async () => {
4058} ) ;
4159
4260test ( "with short with multiple lines should succeed" , async ( ) => {
43- const [ actual ] = bodyMaxLineLength ( await parsed . short , undefined , value ) ;
61+ const [ actual ] = bodyMaxLineLength (
62+ await parsed . shortMultipleLines ,
63+ undefined ,
64+ value ,
65+ ) ;
4466 const expected = true ;
4567 expect ( actual ) . toEqual ( expected ) ;
4668} ) ;
4769
4870test ( "with long with multiple lines should fail" , async ( ) => {
49- const [ actual ] = bodyMaxLineLength ( await parsed . long , undefined , value ) ;
71+ const [ actual ] = bodyMaxLineLength (
72+ await parsed . longMultipleLines ,
73+ undefined ,
74+ value ,
75+ ) ;
5076 const expected = false ;
5177 expect ( actual ) . toEqual ( expected ) ;
5278} ) ;
79+
80+ test ( "with multiple lines and standalone URL should succeed" , async ( ) => {
81+ const [ actual ] = bodyMaxLineLength (
82+ await parsed . urlStandalone ,
83+ undefined ,
84+ value ,
85+ ) ;
86+ const expected = true ;
87+ expect ( actual ) . toEqual ( expected ) ;
88+ } ) ;
89+
90+ test ( "with multiple lines and URL in inline Markdown link should succeed" , async ( ) => {
91+ const [ actual ] = bodyMaxLineLength (
92+ await parsed . urlMarkdownLinkInline ,
93+ undefined ,
94+ 30 ,
95+ ) ;
96+ const expected = true ;
97+ expect ( actual ) . toEqual ( expected ) ;
98+ } ) ;
0 commit comments