1- import { describe , expect , test , beforeAll , afterAll } from 'vitest'
1+ import { describe , expect , test } from 'vitest'
22
33import { runRule } from '@/content-linter/lib/init-test'
44import { frontmatterLandingRecommended } from '@/content-linter/lib/linting-rules/frontmatter-landing-recommended'
@@ -10,28 +10,13 @@ const DUPLICATE_RECOMMENDED =
1010 'src/content-linter/tests/fixtures/landing-recommended/duplicate-recommended.md'
1111const INVALID_PATHS = 'src/content-linter/tests/fixtures/landing-recommended/invalid-paths.md'
1212const 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'
1913
2014const ruleName = frontmatterLandingRecommended . names [ 1 ]
2115
2216// Configure the test fixture to not split frontmatter and content
2317const fmOptions = { markdownlintOptions : { frontMatter : null } }
2418
2519describe ( 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- } )
3520 test ( 'landing page with recommended articles passes' , async ( ) => {
3621 const result = await runRule ( frontmatterLandingRecommended , {
3722 files : [ VALID_LANDING ] ,
@@ -90,61 +75,4 @@ describe(ruleName, () => {
9075 } )
9176 expect ( result [ VALID_LANDING ] ) . toEqual ( [ ] )
9277 } )
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- } )
15078} )
0 commit comments