1+ import { DocusaurusConfig } from "@docusaurus/types" ;
12import {
23 DocInfoWithFilePath ,
34 PostBuildData ,
@@ -6,67 +7,202 @@ import {
67import { processDocInfos } from "./processDocInfos" ;
78
89describe ( "processDocInfos" , ( ) => {
9- const routesPaths : string [ ] = [
10- "/base/" ,
11- "/base/docs/a" ,
12- "/base/blog" ,
13- "/base/blog/tags" ,
14- "/base/blog/b" ,
15- "/base/404.html" ,
16- "/base/page" ,
17- "/base/__meta__.md" ,
18- "/base/file.md" ,
19- ] ;
20- const buildData : PostBuildData = {
21- routesPaths,
22- outDir : "/build" ,
23- baseUrl : "/base/" ,
24- } ;
25- test . each < [ Partial < ProcessedPluginOptions > , DocInfoWithFilePath [ ] ] > ( [
26- [
27- {
28- indexDocs : false ,
29- indexBlog : false ,
30- indexPages : false ,
31- ignoreFiles : [ ] ,
32- } ,
33- [ ] ,
34- ] ,
35- [
36- {
37- indexDocs : true ,
38- indexBlog : true ,
39- indexPages : true ,
40- docsRouteBasePath : [ "docs" ] ,
41- blogRouteBasePath : [ "blog" ] ,
42- ignoreFiles : [ / ^ _ _ m e t a _ _ / , "file.md" ] ,
43- } ,
10+ describe ( "trailingSlash defaults to undefined" , ( ) => {
11+ const routesPaths : string [ ] = [
12+ "/base/" ,
13+ "/base/docs/a" ,
14+ "/base/blog" ,
15+ "/base/blog/tags" ,
16+ "/base/blog/b" ,
17+ "/base/404.html" ,
18+ "/base/page" ,
19+ "/base/__meta__.md" ,
20+ "/base/file.md" ,
21+ ] ;
22+ const buildData : PostBuildData = {
23+ routesPaths,
24+ outDir : "/build" ,
25+ baseUrl : "/base/" ,
26+ } ;
27+ test . each < [ Partial < ProcessedPluginOptions > , DocInfoWithFilePath [ ] ] > ( [
4428 [
4529 {
46- filePath : "/build/index.html" ,
47- type : "page" ,
48- url : "/base/" ,
30+ indexDocs : false ,
31+ indexBlog : false ,
32+ indexPages : false ,
33+ ignoreFiles : [ ] ,
4934 } ,
35+ [ ] ,
36+ ] ,
37+ [
38+ {
39+ indexDocs : true ,
40+ indexBlog : true ,
41+ indexPages : true ,
42+ docsRouteBasePath : [ "docs" ] ,
43+ blogRouteBasePath : [ "blog" ] ,
44+ ignoreFiles : [ / ^ _ _ m e t a _ _ / , "file.md" ] ,
45+ } ,
46+ [
47+ {
48+ filePath : "/build/docs/a/index.html" ,
49+ type : "docs" ,
50+ url : "/base/docs/a" ,
51+ } ,
52+ {
53+ filePath : "/build/blog/b/index.html" ,
54+ type : "blog" ,
55+ url : "/base/blog/b" ,
56+ } ,
57+ {
58+ filePath : "/build/page/index.html" ,
59+ type : "page" ,
60+ url : "/base/page" ,
61+ } ,
62+ ] ,
63+ ] ,
64+ ] ) ( "processDocInfos(...) should work" , ( config , result ) => {
65+ expect (
66+ processDocInfos (
67+ buildData ,
68+ config as ProcessedPluginOptions ,
69+ { } as DocusaurusConfig
70+ )
71+ ) . toEqual ( result ) ;
72+ } ) ;
73+ } ) ;
74+
75+ describe ( "trailingSlash set to false" , ( ) => {
76+ const routesPaths : string [ ] = [
77+ "/base/" ,
78+ "/base/docs/a" ,
79+ "/base/blog" ,
80+ "/base/blog/tags" ,
81+ "/base/blog/b" ,
82+ "/base/404.html" ,
83+ "/base/page" ,
84+ "/base/__meta__.md" ,
85+ "/base/file.md" ,
86+ ] ;
87+ const buildData : PostBuildData = {
88+ routesPaths,
89+ outDir : "/build" ,
90+ baseUrl : "/base/" ,
91+ } ;
92+ test . each < [ Partial < ProcessedPluginOptions > , DocInfoWithFilePath [ ] ] > ( [
93+ [
94+ {
95+ indexDocs : false ,
96+ indexBlog : false ,
97+ indexPages : false ,
98+ ignoreFiles : [ ] ,
99+ } ,
100+ [ ] ,
101+ ] ,
102+ [
50103 {
51- filePath : "/build/docs/a/index.html" ,
52- type : "docs" ,
53- url : "/base/docs/a" ,
104+ indexDocs : true ,
105+ indexBlog : true ,
106+ indexPages : true ,
107+ docsRouteBasePath : [ "docs" ] ,
108+ blogRouteBasePath : [ "blog" ] ,
109+ ignoreFiles : [ / ^ _ _ m e t a _ _ / , "file.md" ] ,
54110 } ,
111+ [
112+ {
113+ filePath : "/build/docs/a.html" ,
114+ type : "docs" ,
115+ url : "/base/docs/a" ,
116+ } ,
117+ {
118+ filePath : "/build/blog/b.html" ,
119+ type : "blog" ,
120+ url : "/base/blog/b" ,
121+ } ,
122+ {
123+ filePath : "/build/page.html" ,
124+ type : "page" ,
125+ url : "/base/page" ,
126+ } ,
127+ ] ,
128+ ] ,
129+ ] ) ( "processDocInfos(...) should work" , ( config , result ) => {
130+ expect (
131+ processDocInfos (
132+ buildData ,
133+ config as ProcessedPluginOptions ,
134+ {
135+ trailingSlash : false ,
136+ } as DocusaurusConfig
137+ )
138+ ) . toEqual ( result ) ;
139+ } ) ;
140+ } ) ;
141+
142+ describe ( "trailingSlash set to true" , ( ) => {
143+ const routesPaths : string [ ] = [
144+ "/base/" ,
145+ "/base/docs/a/" ,
146+ "/base/blog/" ,
147+ "/base/blog/tags/" ,
148+ "/base/blog/b/" ,
149+ "/base/404.html" ,
150+ "/base/page/" ,
151+ "/base/__meta__.md" ,
152+ "/base/file.md" ,
153+ ] ;
154+ const buildData : PostBuildData = {
155+ routesPaths,
156+ outDir : "/build" ,
157+ baseUrl : "/base/" ,
158+ } ;
159+ test . each < [ Partial < ProcessedPluginOptions > , DocInfoWithFilePath [ ] ] > ( [
160+ [
55161 {
56- filePath : "/build/blog/b/index.html" ,
57- type : "blog" ,
58- url : "/base/blog/b" ,
162+ indexDocs : false ,
163+ indexBlog : false ,
164+ indexPages : false ,
165+ ignoreFiles : [ ] ,
59166 } ,
167+ [ ] ,
168+ ] ,
169+ [
60170 {
61- filePath : "/build/page/index.html" ,
62- type : "page" ,
63- url : "/base/page" ,
171+ indexDocs : true ,
172+ indexBlog : true ,
173+ indexPages : true ,
174+ docsRouteBasePath : [ "docs" ] ,
175+ blogRouteBasePath : [ "blog" ] ,
176+ ignoreFiles : [ / ^ _ _ m e t a _ _ / , "file.md" ] ,
64177 } ,
178+ [
179+ {
180+ filePath : "/build/docs/a/index.html" ,
181+ type : "docs" ,
182+ url : "/base/docs/a/" ,
183+ } ,
184+ {
185+ filePath : "/build/blog/b/index.html" ,
186+ type : "blog" ,
187+ url : "/base/blog/b/" ,
188+ } ,
189+ {
190+ filePath : "/build/page/index.html" ,
191+ type : "page" ,
192+ url : "/base/page/" ,
193+ } ,
194+ ] ,
65195 ] ,
66- ] ,
67- ] ) ( "processDocInfos(...) should work" , ( config , result ) => {
68- expect (
69- processDocInfos ( buildData , config as ProcessedPluginOptions )
70- ) . toEqual ( result ) ;
196+ ] ) ( "processDocInfos(...) should work" , ( config , result ) => {
197+ expect (
198+ processDocInfos (
199+ buildData ,
200+ config as ProcessedPluginOptions ,
201+ {
202+ trailingSlash : true ,
203+ } as DocusaurusConfig
204+ )
205+ ) . toEqual ( result ) ;
206+ } ) ;
71207 } ) ;
72208} ) ;
0 commit comments