@@ -15,20 +15,24 @@ Deno.test("lib/helpers.ts: matchRoutes", async () => {
15
15
"./routes/docs/index.mdx" ,
16
16
"./routes/index.tsx" ,
17
17
"./routes/utils.ts" ,
18
- "./routes/post/[date]/[...slug].tsx" ,
19
18
"./routes/works.tsx" ,
20
19
"./routes/works/$id.tsx" ,
21
20
"./routes/works/$id/$page+.tsx" ,
22
21
"./routes/works/$id/index.tsx" ,
23
22
"./routes/works/$id/order.tsx" ,
24
23
"./routes/works/index.tsx" ,
25
24
"./routes/works/new.tsx" ,
25
+ "./routes/users/index.tsx" ,
26
+ "./routes/users/$uid.tsx" ,
27
+ "./routes/users/$uid/index.tsx" ,
28
+ "./routes/users/$uid/settings/$page.tsx" ,
29
+ "./routes/post/[date]/[...slug].tsx" ,
26
30
] ;
27
31
await Promise . all ( files . map ( ( file ) => Deno . mkdir ( join ( tmpDir , dirname ( file ) ) , { recursive : true } ) ) ) ;
28
32
await Promise . all ( files . map ( ( file ) => Deno . writeTextFile ( join ( tmpDir , file ) , "" ) ) ) ;
29
33
const routes = await initRoutes ( "./routes/**/*.{tsx,mdx}" , tmpDir ) ;
30
34
assertEquals ( routes . routes . length , files . length - 1 ) ;
31
- assertEquals ( routes . routes . filter ( ( [ _ , meta ] ) => meta . nesting ) . length , 4 ) ;
35
+ assertEquals ( routes . routes . filter ( ( [ _ , meta ] ) => meta . nesting ) . length , 5 ) ;
32
36
33
37
let matches = matchRoutes ( new URL ( "/" , "http://localhost:3000" ) , routes ) ;
34
38
assertEquals ( matches . map ( ( [ ret ] ) => ret . pathname . input ) , [ "/_app" , "/" ] ) ;
@@ -119,4 +123,30 @@ Deno.test("lib/helpers.ts: matchRoutes", async () => {
119
123
"./routes/works/$id.tsx" ,
120
124
"./routes/works/$id/$page+.tsx" ,
121
125
] ) ;
126
+
127
+ matches = matchRoutes ( new URL ( "/users" , "http://localhost:3000" ) , routes ) ;
128
+ assertEquals ( matches . map ( ( [ ret ] ) => ret . pathname . input ) , [ "/_app" , "/users/index" ] ) ;
129
+ assertEquals ( matches . map ( ( [ ret ] ) => ret . pathname . groups ) , [ { } , { } ] ) ;
130
+ assertEquals ( matches . map ( ( [ _ , meta ] ) => meta . filename ) , [
131
+ "./routes/_app.tsx" ,
132
+ "./routes/users/index.tsx" ,
133
+ ] ) ;
134
+
135
+ matches = matchRoutes ( new URL ( "/users/ije" , "http://localhost:3000" ) , routes ) ;
136
+ assertEquals ( matches . map ( ( [ ret ] ) => ret . pathname . input ) , [ "/_app" , "/users/ije" , "/users/ije/index" ] ) ;
137
+ assertEquals ( matches . map ( ( [ ret ] ) => ret . pathname . groups ) , [ { } , { uid : "ije" } , { uid : "ije" } ] ) ;
138
+ assertEquals ( matches . map ( ( [ _ , meta ] ) => meta . filename ) , [
139
+ "./routes/_app.tsx" ,
140
+ "./routes/users/$uid.tsx" ,
141
+ "./routes/users/$uid/index.tsx" ,
142
+ ] ) ;
143
+
144
+ matches = matchRoutes ( new URL ( "/users/ije/settings/profile" , "http://localhost:3000" ) , routes ) ;
145
+ assertEquals ( matches . map ( ( [ ret ] ) => ret . pathname . input ) , [ "/_app" , "/users/ije" , "/users/ije/settings/profile" ] ) ;
146
+ assertEquals ( matches . map ( ( [ ret ] ) => ret . pathname . groups ) , [ { } , { uid : "ije" } , { uid : "ije" , page : "profile" } ] ) ;
147
+ assertEquals ( matches . map ( ( [ _ , meta ] ) => meta . filename ) , [
148
+ "./routes/_app.tsx" ,
149
+ "./routes/users/$uid.tsx" ,
150
+ "./routes/users/$uid/settings/$page.tsx" ,
151
+ ] ) ;
122
152
} ) ;
0 commit comments