1
- import { describe , expect , test } from 'vitest'
1
+ import { describe , expect , test , beforeAll , afterAll } from 'vitest'
2
2
3
3
import { runRule } from '@/content-linter/lib/init-test'
4
4
import { frontmatterLandingRecommended } from '@/content-linter/lib/linting-rules/frontmatter-landing-recommended'
@@ -10,13 +10,28 @@ const DUPLICATE_RECOMMENDED =
10
10
'src/content-linter/tests/fixtures/landing-recommended/duplicate-recommended.md'
11
11
const INVALID_PATHS = 'src/content-linter/tests/fixtures/landing-recommended/invalid-paths.md'
12
12
const NO_RECOMMENDED = 'src/content-linter/tests/fixtures/landing-recommended/no-recommended.md'
13
+ const ABSOLUTE_PRIORITY =
14
+ 'src/content-linter/tests/fixtures/landing-recommended/test-absolute-priority.md'
15
+ const PATH_PRIORITY = 'src/content-linter/tests/fixtures/landing-recommended/test-path-priority.md'
16
+ const ABSOLUTE_ONLY = 'src/content-linter/tests/fixtures/landing-recommended/test-absolute-only.md'
17
+ const PRIORITY_VALIDATION =
18
+ 'src/content-linter/tests/fixtures/landing-recommended/test-priority-validation.md'
13
19
14
20
const ruleName = frontmatterLandingRecommended . names [ 1 ]
15
21
16
22
// Configure the test fixture to not split frontmatter and content
17
23
const fmOptions = { markdownlintOptions : { frontMatter : null } }
18
24
19
25
describe ( ruleName , ( ) => {
26
+ const envVarValueBefore = process . env . ROOT
27
+
28
+ beforeAll ( ( ) => {
29
+ process . env . ROOT = 'src/fixtures/fixtures'
30
+ } )
31
+
32
+ afterAll ( ( ) => {
33
+ process . env . ROOT = envVarValueBefore
34
+ } )
20
35
test ( 'landing page with recommended articles passes' , async ( ) => {
21
36
const result = await runRule ( frontmatterLandingRecommended , {
22
37
files : [ VALID_LANDING ] ,
@@ -75,4 +90,61 @@ describe(ruleName, () => {
75
90
} )
76
91
expect ( result [ VALID_LANDING ] ) . toEqual ( [ ] )
77
92
} )
93
+
94
+ test ( 'absolute paths are prioritized over relative paths' , async ( ) => {
95
+ // This test verifies that when both absolute and relative paths exist with the same name,
96
+ // the absolute path is chosen over the relative path.
97
+ //
98
+ // Setup:
99
+ // - /article-one should resolve to src/fixtures/fixtures/content/article-one.md (absolute)
100
+ // - article-one (relative) would resolve to src/content-linter/tests/fixtures/landing-recommended/article-one.md
101
+ //
102
+ // The test passes because our logic prioritizes the absolute path resolution first
103
+ const result = await runRule ( frontmatterLandingRecommended , {
104
+ files : [ ABSOLUTE_PRIORITY ] ,
105
+ ...fmOptions ,
106
+ } )
107
+ expect ( result [ ABSOLUTE_PRIORITY ] ) . toEqual ( [ ] )
108
+ } )
109
+
110
+ test ( 'path priority resolution works correctly' , async ( ) => {
111
+ // This test verifies that absolute paths are prioritized over relative paths
112
+ // when both files exist with the same name.
113
+ //
114
+ // Setup:
115
+ // - /article-one could resolve to EITHER:
116
+ // 1. src/fixtures/fixtures/content/article-one.md (absolute - should be chosen)
117
+ // 2. src/content-linter/tests/fixtures/landing-recommended/article-one.md (relative - should be ignored)
118
+ //
119
+ // Our prioritization logic should choose #1 (absolute) over #2 (relative)
120
+ // This test passes because the absolute path exists and is found first
121
+ const result = await runRule ( frontmatterLandingRecommended , {
122
+ files : [ PATH_PRIORITY ] ,
123
+ ...fmOptions ,
124
+ } )
125
+ expect ( result [ PATH_PRIORITY ] ) . toEqual ( [ ] )
126
+ } )
127
+
128
+ test ( 'absolute-only paths work when no relative path exists' , async ( ) => {
129
+ // This test verifies that absolute path resolution works when no relative path exists
130
+ // /article-two exists in src/fixtures/fixtures/content/article-two.md
131
+ // but NOT in src/content-linter/tests/fixtures/landing-recommended/article-two.md
132
+ // This test would fail if we didn't prioritize absolute paths properly
133
+ const result = await runRule ( frontmatterLandingRecommended , {
134
+ files : [ ABSOLUTE_ONLY ] ,
135
+ ...fmOptions ,
136
+ } )
137
+ expect ( result [ ABSOLUTE_ONLY ] ) . toEqual ( [ ] )
138
+ } )
139
+
140
+ test ( 'mixed valid and invalid absolute paths are handled correctly' , async ( ) => {
141
+ // This test has both a valid absolute path (/article-one) and an invalid one (/nonexistent-absolute)
142
+ // It should fail because of the invalid path, proving our absolute path resolution is working
143
+ const result = await runRule ( frontmatterLandingRecommended , {
144
+ files : [ PRIORITY_VALIDATION ] ,
145
+ ...fmOptions ,
146
+ } )
147
+ expect ( result [ PRIORITY_VALIDATION ] ) . toHaveLength ( 1 )
148
+ expect ( result [ PRIORITY_VALIDATION ] [ 0 ] . errorDetail ) . toContain ( 'nonexistent-absolute' )
149
+ } )
78
150
} )
0 commit comments