11import { describe , expect , test } from 'bun:test'
22import type { Folder , Item , Root } from 'fumadocs-core/page-tree'
33import {
4+ type ContentStorage ,
5+ type ContentStorageMetaFile ,
46 type ContentStoragePageFile ,
57 FileSystem ,
8+ type PageData as FumadocsPageData ,
69 type PageTreeBuilderContext ,
7- type SourceConfig ,
810} from 'fumadocs-core/source'
911import { createApiReferenceTreePlugin } from '@/lib/source/api-reference-tree-plugin'
1012import { createPlatformLabelPlugin } from '@/lib/source/platform-label-plugin'
1113
12- type PageData = {
14+ type TestPageData = FumadocsPageData & {
1315 title : string
1416 hybridParent ?: string
1517 platforms ?: string [ ]
1618}
1719
18- type PageFile = {
20+ type PageFile = ContentStoragePageFile < undefined , TestPageData >
21+ type PageFileInput = {
1922 format : 'page'
20- data : PageData
21- }
22-
23- type TestSourceConfig = SourceConfig & {
24- pageData : PageData
25- }
26-
27- type TestLoaderConfig = {
28- source : TestSourceConfig
29- i18n : undefined
23+ data : TestPageData
3024}
25+ type TestStorage = ContentStorage < PageFile , ContentStorageMetaFile >
3126
3227function createPage ( file : string , title : string ) : Item {
3328 return {
3429 $id : file ,
35- $ref : { file } ,
30+ $ref : file ,
3631 type : 'page' ,
3732 name : title ,
3833 url : `/api/${ title } ` ,
3934 }
4035}
4136
4237function createContext (
43- files : Record < string , PageFile > ,
44- ) : PageTreeBuilderContext < TestSourceConfig > {
45- const storage = new FileSystem < ContentStoragePageFile < TestSourceConfig > > ( )
38+ files : Record < string , PageFileInput > ,
39+ ) : PageTreeBuilderContext < TestStorage > {
40+ const storage = new FileSystem <
41+ PageFile | ContentStorageMetaFile
42+ > ( ) as TestStorage
4643
4744 for ( const [ filePath , file ] of Object . entries ( files ) ) {
4845 storage . write ( filePath , {
46+ type : undefined ,
4947 path : filePath ,
5048 format : 'page' ,
5149 slugs : [ file . data . title ] ,
@@ -55,27 +53,29 @@ function createContext(
5553
5654 const getUrl = ( ) => ''
5755 // Fumadocs exposes PageTreeBuilder in its type surface, but not from the runtime module.
58- const builder = { } as PageTreeBuilderContext < TestSourceConfig > [ 'builder' ]
56+ const builder = { } as PageTreeBuilderContext < TestStorage > [ 'builder' ]
5957 return {
60- idPrefix : 'test' ,
61- noRef : false ,
6258 transformers : [ ] ,
6359 builder,
6460 storage,
65- getUrl,
61+ options : {
62+ idPrefix : 'test' ,
63+ noRef : false ,
64+ url : getUrl ,
65+ } ,
6666 }
6767}
6868
6969function getNodeTitle (
7070 node : Folder [ 'children' ] [ number ] ,
71- files : Record < string , PageFile > ,
71+ files : Record < string , PageFileInput > ,
7272) : string {
73- if ( node . type === 'folder' && node . index ?. $ref ?. file ) {
74- return files [ node . index . $ref . file ] ?. data . title ?? ''
73+ if ( node . type === 'folder' && node . index ?. $ref ) {
74+ return files [ node . index . $ref ] ?. data . title ?? ''
7575 }
7676
77- if ( node . type === 'page' && node . $ref ?. file ) {
78- return files [ node . $ref . file ] ?. data . title ?? ''
77+ if ( node . type === 'page' && node . $ref ) {
78+ return files [ node . $ref ] ?. data . title ?? ''
7979 }
8080
8181 return ''
@@ -94,7 +94,7 @@ function getFolderByTitle(root: Root, title: string): Folder {
9494
9595function getChildFolderByTitle (
9696 folder : Folder ,
97- files : Record < string , PageFile > ,
97+ files : Record < string , PageFileInput > ,
9898 title : string ,
9999) : Folder {
100100 const child = folder . children . find (
@@ -110,7 +110,7 @@ function getChildFolderByTitle(
110110
111111describe ( 'api reference tree plugin' , ( ) => {
112112 test ( 'nests platform-labeled hybrid children under their stable hybrid parent' , ( ) => {
113- const files : Record < string , PageFile > = {
113+ const files : Record < string , PageFileInput > = {
114114 'CameraOutput.mdx' : {
115115 format : 'page' ,
116116 data : { title : 'CameraOutput' } ,
@@ -181,8 +181,8 @@ describe('api reference tree plugin', () => {
181181 }
182182
183183 const context = createContext ( files )
184- const apiTreePlugin = createApiReferenceTreePlugin < TestLoaderConfig > ( )
185- const platformLabelPlugin = createPlatformLabelPlugin < TestLoaderConfig > ( )
184+ const apiTreePlugin = createApiReferenceTreePlugin < TestStorage > ( )
185+ const platformLabelPlugin = createPlatformLabelPlugin < TestStorage > ( )
186186 const transformApiTree = apiTreePlugin . transformPageTree ?. root
187187 const transformPlatformLabels = platformLabelPlugin . transformPageTree ?. root
188188
0 commit comments