@@ -1164,6 +1164,54 @@ Deno.test("fsRoutes - sortRoutePaths", () => {
11641164 expect ( routes ) . toEqual ( sorted ) ;
11651165} ) ;
11661166
1167+ Deno . test ( "fsRoutes - sortRoutePaths with groups" , ( ) => {
1168+ let routes = [
1169+ "/(authed)/_middleware.ts" ,
1170+ "/(authed)/index.ts" ,
1171+ "/about.tsx" ,
1172+ ] ;
1173+ routes . sort ( sortRoutePaths ) ;
1174+ let sorted = [
1175+ "/about.tsx" ,
1176+ "/(authed)/_middleware.ts" ,
1177+ "/(authed)/index.ts" ,
1178+ ] ;
1179+ expect ( routes ) . toEqual ( sorted ) ;
1180+
1181+ routes = [
1182+ "/_app" ,
1183+ "/(authed)/_middleware" ,
1184+ "/(authed)/_layout" ,
1185+ "/_error" ,
1186+ "/(authed)/index" ,
1187+ "/login" ,
1188+ "/auth/login" ,
1189+ "/auth/logout" ,
1190+ "/(authed)/(account)/account" ,
1191+ "/(authed)/api/slug" ,
1192+ "/hooks/github" ,
1193+ "/(authed)/[org]/_middleware" ,
1194+ "/(authed)/[org]/index" ,
1195+ ] ;
1196+ routes . sort ( sortRoutePaths ) ;
1197+ sorted = [
1198+ "/_app" ,
1199+ "/_error" ,
1200+ "/login" ,
1201+ "/auth/login" ,
1202+ "/auth/logout" ,
1203+ "/hooks/github" ,
1204+ "/(authed)/_middleware" ,
1205+ "/(authed)/_layout" ,
1206+ "/(authed)/index" ,
1207+ "/(authed)/api/slug" ,
1208+ "/(authed)/(account)/account" ,
1209+ "/(authed)/[org]/_middleware" ,
1210+ "/(authed)/[org]/index" ,
1211+ ] ;
1212+ expect ( routes ) . toEqual ( sorted ) ;
1213+ } ) ;
1214+
11671215Deno . test ( "fsRoutes - registers default GET route for component without GET handler" , async ( ) => {
11681216 const server = await createServer < { value : boolean } > ( {
11691217 "routes/noGetHandler.tsx" : {
@@ -1193,6 +1241,47 @@ Deno.test("fsRoutes - registers default GET route for component without GET hand
11931241 ) ;
11941242} ) ;
11951243
1244+ Deno . test ( "fsRoutes - default GET route works with nested middleware" , async ( ) => {
1245+ const server = await createServer < { text : string } > ( {
1246+ "routes/_middleware.ts" : {
1247+ handler : ( ctx ) => {
1248+ ctx . state . text = "A" ;
1249+ return ctx . next ( ) ;
1250+ } ,
1251+ } ,
1252+ "routes/foo/_middleware.ts" : {
1253+ handler : ( ctx ) => {
1254+ ctx . state . text += "B" ;
1255+ return ctx . next ( ) ;
1256+ } ,
1257+ } ,
1258+ "routes/foo/noGetHandler.tsx" : {
1259+ default : ( ctx ) => {
1260+ return < h1 > { ctx . state . text } </ h1 > ;
1261+ } ,
1262+ handlers : {
1263+ POST : ( ) => new Response ( "POST" ) ,
1264+ } ,
1265+ } ,
1266+ } ) ;
1267+
1268+ const postRes = await server . post ( "/foo/noGetHandler" ) ;
1269+ expect ( postRes . status ) . toEqual ( 200 ) ;
1270+ expect ( postRes . headers . get ( "Content-Type" ) ) . toEqual (
1271+ "text/plain;charset=UTF-8" ,
1272+ ) ;
1273+ expect ( await postRes . text ( ) ) . toEqual ( "POST" ) ;
1274+
1275+ const getRes = await server . get ( "/foo/noGetHandler" ) ;
1276+ expect ( getRes . status ) . toEqual ( 200 ) ;
1277+ expect ( getRes . headers . get ( "Content-Type" ) ) . toEqual (
1278+ "text/html; charset=utf-8" ,
1279+ ) ;
1280+ expect ( await getRes . text ( ) ) . toContain (
1281+ "<h1>AB</h1>" ,
1282+ ) ;
1283+ } ) ;
1284+
11961285Deno . test ( "fsRoutes - default GET route doesn't override existing handler" , async ( ) => {
11971286 const server = await createServer < { value : boolean } > ( {
11981287 "routes/withGetHandler.tsx" : {
0 commit comments