@@ -1212,6 +1212,54 @@ Deno.test("fsRoutes - sortRoutePaths", () => {
1212
1212
expect ( routes ) . toEqual ( sorted ) ;
1213
1213
} ) ;
1214
1214
1215
+ Deno . test ( "fsRoutes - sortRoutePaths with groups" , ( ) => {
1216
+ let routes = [
1217
+ "/(authed)/_middleware.ts" ,
1218
+ "/(authed)/index.ts" ,
1219
+ "/about.tsx" ,
1220
+ ] ;
1221
+ routes . sort ( sortRoutePaths ) ;
1222
+ let sorted = [
1223
+ "/about.tsx" ,
1224
+ "/(authed)/_middleware.ts" ,
1225
+ "/(authed)/index.ts" ,
1226
+ ] ;
1227
+ expect ( routes ) . toEqual ( sorted ) ;
1228
+
1229
+ routes = [
1230
+ "/_app" ,
1231
+ "/(authed)/_middleware" ,
1232
+ "/(authed)/_layout" ,
1233
+ "/_error" ,
1234
+ "/(authed)/index" ,
1235
+ "/login" ,
1236
+ "/auth/login" ,
1237
+ "/auth/logout" ,
1238
+ "/(authed)/(account)/account" ,
1239
+ "/(authed)/api/slug" ,
1240
+ "/hooks/github" ,
1241
+ "/(authed)/[org]/_middleware" ,
1242
+ "/(authed)/[org]/index" ,
1243
+ ] ;
1244
+ routes . sort ( sortRoutePaths ) ;
1245
+ sorted = [
1246
+ "/_app" ,
1247
+ "/_error" ,
1248
+ "/login" ,
1249
+ "/auth/login" ,
1250
+ "/auth/logout" ,
1251
+ "/hooks/github" ,
1252
+ "/(authed)/_middleware" ,
1253
+ "/(authed)/_layout" ,
1254
+ "/(authed)/index" ,
1255
+ "/(authed)/api/slug" ,
1256
+ "/(authed)/(account)/account" ,
1257
+ "/(authed)/[org]/_middleware" ,
1258
+ "/(authed)/[org]/index" ,
1259
+ ] ;
1260
+ expect ( routes ) . toEqual ( sorted ) ;
1261
+ } ) ;
1262
+
1215
1263
Deno . test ( "fsRoutes - registers default GET route for component without GET handler" , async ( ) => {
1216
1264
const server = await createServer < { value : boolean } > ( {
1217
1265
"routes/noGetHandler.tsx" : {
@@ -1241,6 +1289,47 @@ Deno.test("fsRoutes - registers default GET route for component without GET hand
1241
1289
) ;
1242
1290
} ) ;
1243
1291
1292
+ Deno . test ( "fsRoutes - default GET route works with nested middleware" , async ( ) => {
1293
+ const server = await createServer < { text : string } > ( {
1294
+ "routes/_middleware.ts" : {
1295
+ handler : ( ctx ) => {
1296
+ ctx . state . text = "A" ;
1297
+ return ctx . next ( ) ;
1298
+ } ,
1299
+ } ,
1300
+ "routes/foo/_middleware.ts" : {
1301
+ handler : ( ctx ) => {
1302
+ ctx . state . text += "B" ;
1303
+ return ctx . next ( ) ;
1304
+ } ,
1305
+ } ,
1306
+ "routes/foo/noGetHandler.tsx" : {
1307
+ default : ( ctx ) => {
1308
+ return < h1 > { ctx . state . text } </ h1 > ;
1309
+ } ,
1310
+ handlers : {
1311
+ POST : ( ) => new Response ( "POST" ) ,
1312
+ } ,
1313
+ } ,
1314
+ } ) ;
1315
+
1316
+ const postRes = await server . post ( "/foo/noGetHandler" ) ;
1317
+ expect ( postRes . status ) . toEqual ( 200 ) ;
1318
+ expect ( postRes . headers . get ( "Content-Type" ) ) . toEqual (
1319
+ "text/plain;charset=UTF-8" ,
1320
+ ) ;
1321
+ expect ( await postRes . text ( ) ) . toEqual ( "POST" ) ;
1322
+
1323
+ const getRes = await server . get ( "/foo/noGetHandler" ) ;
1324
+ expect ( getRes . status ) . toEqual ( 200 ) ;
1325
+ expect ( getRes . headers . get ( "Content-Type" ) ) . toEqual (
1326
+ "text/html; charset=utf-8" ,
1327
+ ) ;
1328
+ expect ( await getRes . text ( ) ) . toContain (
1329
+ "<h1>AB</h1>" ,
1330
+ ) ;
1331
+ } ) ;
1332
+
1244
1333
Deno . test ( "fsRoutes - default GET route doesn't override existing handler" , async ( ) => {
1245
1334
const server = await createServer < { value : boolean } > ( {
1246
1335
"routes/withGetHandler.tsx" : {
0 commit comments