1
1
import { test , expect } from "vitest" ;
2
2
import parse from "@commitlint/parse" ;
3
+ import type { Commit } from "conventional-commits-parser" ;
3
4
import { bodyMaxLineLength } from "./body-max-line-length.js" ;
4
5
5
6
const short = "a" ;
6
7
const long = "ab" ;
8
+ const url = "https://example.com/URL/with/a/very/long/path" ;
7
9
8
10
const value = short . length ;
9
11
@@ -13,14 +15,30 @@ const messages = {
13
15
long : `test: subject\n${ long } ` ,
14
16
shortMultipleLines : `test:subject\n${ short } \n${ short } \n${ short } ` ,
15
17
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
17
28
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 } ` ,
22
32
} ;
23
33
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
+
24
42
test ( "with empty should succeed" , async ( ) => {
25
43
const [ actual ] = bodyMaxLineLength ( await parsed . empty , undefined , value ) ;
26
44
const expected = true ;
@@ -40,13 +58,41 @@ test("with long should fail", async () => {
40
58
} ) ;
41
59
42
60
test ( "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
+ ) ;
44
66
const expected = true ;
45
67
expect ( actual ) . toEqual ( expected ) ;
46
68
} ) ;
47
69
48
70
test ( "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
+ ) ;
50
76
const expected = false ;
51
77
expect ( actual ) . toEqual ( expected ) ;
52
78
} ) ;
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