@@ -6,6 +6,7 @@ import { extractMarkdownFiles, updateSources, addLocalPath, removePath, isPathCo
66import type { RefdocsConfig } from "../src/types.js" ;
77
88const FIXTURE_PATH = join ( import . meta. dirname , "fixtures" , "test-repo.tar.gz" ) ;
9+ const MDX_FIXTURE_PATH = join ( import . meta. dirname , "fixtures" , "test-repo-mdx.tar.gz" ) ;
910
1011describe ( "extractMarkdownFiles" , ( ) => {
1112 let tmpDir : string ;
@@ -70,6 +71,27 @@ describe("extractMarkdownFiles", () => {
7071 const count = await extractMarkdownFiles ( tarball , "nonexistent" , join ( tmpDir , "out" ) ) ;
7172 expect ( count ) . toBe ( 0 ) ;
7273 } ) ;
74+
75+ it ( "extracts .mdx files alongside .md files" , async ( ) => {
76+ const mdxTarball = readFileSync ( MDX_FIXTURE_PATH ) ;
77+ const count = await extractMarkdownFiles ( mdxTarball , "" , join ( tmpDir , "out" ) ) ;
78+ expect ( count ) . toBe ( 3 ) ;
79+
80+ expect ( existsSync ( join ( tmpDir , "out" , "docs" , "guide.md" ) ) ) . toBe ( true ) ;
81+ expect ( existsSync ( join ( tmpDir , "out" , "docs" , "component.mdx" ) ) ) . toBe ( true ) ;
82+ expect ( existsSync ( join ( tmpDir , "out" , "docs" , "page.mdx" ) ) ) . toBe ( true ) ;
83+ expect ( existsSync ( join ( tmpDir , "out" , "package.json" ) ) ) . toBe ( false ) ;
84+ } ) ;
85+
86+ it ( "filters .mdx files by subpath" , async ( ) => {
87+ const mdxTarball = readFileSync ( MDX_FIXTURE_PATH ) ;
88+ const count = await extractMarkdownFiles ( mdxTarball , "docs" , join ( tmpDir , "out" ) ) ;
89+ expect ( count ) . toBe ( 3 ) ;
90+
91+ expect ( existsSync ( join ( tmpDir , "out" , "guide.md" ) ) ) . toBe ( true ) ;
92+ expect ( existsSync ( join ( tmpDir , "out" , "component.mdx" ) ) ) . toBe ( true ) ;
93+ expect ( existsSync ( join ( tmpDir , "out" , "page.mdx" ) ) ) . toBe ( true ) ;
94+ } ) ;
7395} ) ;
7496
7597vi . mock ( "../src/github.js" , async ( importOriginal ) => {
@@ -261,12 +283,21 @@ describe("addLocalPath", () => {
261283 expect ( ( ) => addLocalPath ( "nope" , tmpDir , baseConfig ) ) . toThrow ( "Directory not found: nope" ) ;
262284 } ) ;
263285
264- it ( "throws if directory has no .md files" , ( ) => {
286+ it ( "throws if directory has no .md/.mdx files" , ( ) => {
265287 const emptyDir = join ( tmpDir , "empty" ) ;
266288 mkdirSync ( emptyDir , { recursive : true } ) ;
267289 writeFileSync ( join ( emptyDir , "data.json" ) , "{}" ) ;
268290
269- expect ( ( ) => addLocalPath ( "empty" , tmpDir , baseConfig ) ) . toThrow ( "No .md files found" ) ;
291+ expect ( ( ) => addLocalPath ( "empty" , tmpDir , baseConfig ) ) . toThrow ( "No .md/.mdx files found" ) ;
292+ } ) ;
293+
294+ it ( "accepts a directory with only .mdx files" , ( ) => {
295+ const mdxDir = join ( tmpDir , "mdx-docs" ) ;
296+ mkdirSync ( mdxDir , { recursive : true } ) ;
297+ writeFileSync ( join ( mdxDir , "page.mdx" ) , "# MDX Page" ) ;
298+
299+ const result = addLocalPath ( "mdx-docs" , tmpDir , baseConfig ) ;
300+ expect ( result . localPath ) . toBe ( "mdx-docs" ) ;
270301 } ) ;
271302
272303 it ( "finds .md files in subdirectories" , ( ) => {
0 commit comments