@@ -29,92 +29,126 @@ test("ensure the rule validates correctly", async (t) => {
29
29
name : "should be invalid with an empty id fragment" ,
30
30
fixturePath :
31
31
"test/fixtures/invalid/empty-id-fragment/empty-id-fragment.md" ,
32
- error : '"./awesome.md#" should have a valid fragment identifier' ,
32
+ errors : [ '"./awesome.md#" should have a valid fragment identifier' ] ,
33
33
} ,
34
34
{
35
35
name : "should be invalid with a name fragment other than for an anchor" ,
36
36
fixturePath :
37
37
"test/fixtures/invalid/ignore-name-fragment-if-not-an-anchor/ignore-name-fragment-if-not-an-anchor.md" ,
38
- error :
38
+ errors : [
39
39
'"./awesome.md#name-should-be-ignored" should have a valid fragment identifier' ,
40
+ ] ,
40
41
} ,
41
42
{
42
43
name : "should be invalid with a non-existing id fragment (data-id !== id)" ,
43
44
fixturePath :
44
45
"test/fixtures/invalid/ignore-not-an-id-fragment/ignore-not-an-id-fragment.md" ,
45
- error :
46
+ errors : [
46
47
'"./awesome.md#not-an-id-should-be-ignored" should have a valid fragment identifier' ,
48
+ ] ,
47
49
} ,
48
50
{
49
51
name : "should be invalid with invalid heading with #L fragment" ,
50
52
fixturePath :
51
53
"test/fixtures/invalid/invalid-heading-with-L-fragment/invalid-heading-with-L-fragment.md" ,
52
- error : '"./awesome.md#L7abc" should have a valid fragment identifier' ,
54
+ errors : [
55
+ '"./awesome.md#L7abc" should have a valid fragment identifier' ,
56
+ ] ,
57
+ } ,
58
+ {
59
+ name : "should be invalid with a invalid line column range number fragment" ,
60
+ fixturePath :
61
+ "test/fixtures/invalid/invalid-line-column-range-number-fragment/invalid-line-column-range-number-fragment.md" ,
62
+ errors : [
63
+ '"./awesome.md#L12-not-a-line-link" should have a valid fragment identifier' ,
64
+ '"./awesome.md#l7" should have a valid fragment identifier' ,
65
+ '"./awesome.md#L" should have a valid fragment identifier' ,
66
+ '"./awesome.md#L7extra" should have a valid fragment identifier' ,
67
+ '"./awesome.md#L30C" should have a valid fragment identifier' ,
68
+ '"./awesome.md#L30Cextra" should have a valid fragment identifier' ,
69
+ '"./awesome.md#L30L12" should have a valid fragment identifier' ,
70
+ '"./awesome.md#L30C12" should have a valid fragment identifier' ,
71
+ '"./awesome.md#L30C11-" should have a valid fragment identifier' ,
72
+ '"./awesome.md#L30C11-L" should have a valid fragment identifier' ,
73
+ '"./awesome.md#L30C11-L31C" should have a valid fragment identifier' ,
74
+ '"./awesome.md#L30C11-C31" should have a valid fragment identifier' ,
75
+ '"./awesome.md#C30" should have a valid fragment identifier' ,
76
+ '"./awesome.md#C11-C31" should have a valid fragment identifier' ,
77
+ '"./awesome.md#C11-L4C31" should have a valid fragment identifier' ,
78
+ ] ,
53
79
} ,
54
80
{
55
81
name : "should be invalid with a invalid line number fragment" ,
56
82
fixturePath :
57
83
"test/fixtures/invalid/invalid-line-number-fragment/invalid-line-number-fragment.md" ,
58
- error :
84
+ errors : [
59
85
'"./awesome.md#L7" should have a valid fragment identifier, "./awesome.md#L7" should have at least 7 lines to be valid' ,
86
+ ] ,
60
87
} ,
61
88
{
62
89
name : "should be invalid with a non-existing anchor name fragment" ,
63
90
fixturePath :
64
91
"test/fixtures/invalid/non-existing-anchor-name-fragment/non-existing-anchor-name-fragment.md" ,
65
- error :
92
+ errors : [
66
93
'"./awesome.md#non-existing-anchor-name-fragment" should have a valid fragment identifier' ,
94
+ ] ,
67
95
} ,
68
96
{
69
97
name : "should be invalid with a non-existing element id fragment" ,
70
98
fixturePath :
71
99
"test/fixtures/invalid/non-existing-element-id-fragment/non-existing-element-id-fragment.md" ,
72
- error :
100
+ errors : [
73
101
'"./awesome.md#non-existing-element-id-fragment" should have a valid fragment identifier' ,
102
+ ] ,
74
103
} ,
75
104
{
76
105
name : "should be invalid with a non-existing heading fragment" ,
77
106
fixturePath :
78
107
"test/fixtures/invalid/non-existing-heading-fragment/non-existing-heading-fragment.md" ,
79
- error :
108
+ errors : [
80
109
'"./awesome.md#non-existing-heading" should have a valid fragment identifier' ,
110
+ ] ,
81
111
} ,
82
112
{
83
113
name : "should be invalid with a link to an image with a empty fragment" ,
84
114
fixturePath :
85
115
"test/fixtures/invalid/ignore-empty-fragment-checking-for-image.md" ,
86
- error :
116
+ errors : [
87
117
'"../image.png#" should not have a fragment identifier as it is an image' ,
118
+ ] ,
88
119
} ,
89
120
{
90
121
name : "should be invalid with a link to an image with a fragment" ,
91
122
fixturePath :
92
123
"test/fixtures/invalid/ignore-fragment-checking-for-image.md" ,
93
- error :
124
+ errors : [
94
125
'"../image.png#non-existing-fragment" should not have a fragment identifier as it is an image' ,
126
+ ] ,
95
127
} ,
96
128
{
97
129
name : "should be invalid with a non-existing file" ,
98
130
fixturePath : "test/fixtures/invalid/non-existing-file.md" ,
99
- error : '"./index.test.js" should exist in the file system' ,
131
+ errors : [ '"./index.test.js" should exist in the file system' ] ,
100
132
} ,
101
133
{
102
134
name : "should be invalid with a non-existing image" ,
103
135
fixturePath : "test/fixtures/invalid/non-existing-image.md" ,
104
- error : '"./image.png" should exist in the file system' ,
136
+ errors : [ '"./image.png" should exist in the file system' ] ,
105
137
} ,
106
138
]
107
139
108
- for ( const { name, fixturePath, error } of testCases ) {
140
+ for ( const { name, fixturePath, errors } of testCases ) {
109
141
await t . test ( name , async ( ) => {
110
- const lintResults = await validateMarkdownLint ( fixturePath )
111
- assert . equal ( lintResults ?. length , 1 )
112
- assert . deepEqual ( lintResults ?. [ 0 ] ?. ruleNames , relativeLinksRule . names )
113
- assert . equal (
114
- lintResults ?. [ 0 ] ?. ruleDescription ,
115
- relativeLinksRule . description ,
116
- )
117
- assert . equal ( lintResults ?. [ 0 ] ?. errorDetail , error )
142
+ const lintResults = ( await validateMarkdownLint ( fixturePath ) ) ?? [ ]
143
+ const errorsDetails = lintResults . map ( ( result ) => {
144
+ assert . deepEqual ( result . ruleNames , relativeLinksRule . names )
145
+ assert . deepEqual (
146
+ result . ruleDescription ,
147
+ relativeLinksRule . description ,
148
+ )
149
+ return result . errorDetail
150
+ } )
151
+ assert . deepStrictEqual ( errorsDetails , errors )
118
152
} )
119
153
}
120
154
} )
@@ -151,6 +185,11 @@ test("ensure the rule validates correctly", async (t) => {
151
185
fixturePath :
152
186
"test/fixtures/valid/only-parse-markdown-files-for-fragments/only-parse-markdown-files-for-fragments.md" ,
153
187
} ,
188
+ {
189
+ name : "should support lines and columns range numbers in link fragments" ,
190
+ fixturePath :
191
+ "test/fixtures/valid/valid-line-column-range-number-fragment/valid-line-column-range-number-fragment.md" ,
192
+ } ,
154
193
{
155
194
name : 'should be valid with valid heading "like" line number fragment' ,
156
195
fixturePath :
@@ -186,8 +225,15 @@ test("ensure the rule validates correctly", async (t) => {
186
225
187
226
for ( const { name, fixturePath } of testCases ) {
188
227
await t . test ( name , async ( ) => {
189
- const lintResults = await validateMarkdownLint ( fixturePath )
190
- assert . equal ( lintResults ?. length , 0 )
228
+ const lintResults = ( await validateMarkdownLint ( fixturePath ) ) ?? [ ]
229
+ const errorsDetails = lintResults . map ( ( result ) => {
230
+ return result . errorDetail
231
+ } )
232
+ assert . equal (
233
+ errorsDetails . length ,
234
+ 0 ,
235
+ `Expected no errors, got ${ errorsDetails . join ( ", " ) } ` ,
236
+ )
191
237
} )
192
238
}
193
239
} )
0 commit comments