From 3681fb1c8499143128324a335d26ce76c806c681 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Thu, 23 Oct 2025 13:05:11 +0200 Subject: [PATCH] fix: `.fsRoutes()` pattern argument not working (#3571) Fixes https://github.com/denoland/fresh/issues/3566 --- packages/fresh/src/commands.ts | 3 ++- packages/fresh/src/fs_routes_test.tsx | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/fresh/src/commands.ts b/packages/fresh/src/commands.ts index b6979f58..87be2279 100644 --- a/packages/fresh/src/commands.ts +++ b/packages/fresh/src/commands.ts @@ -357,7 +357,8 @@ function applyCommandsInner( } case CommandType.FsRoute: { const items = cmd.getItems(); - applyCommandsInner(root, router, items, basePath); + const base = mergePath(basePath, cmd.pattern, true); + applyCommandsInner(root, router, items, base); break; } default: diff --git a/packages/fresh/src/fs_routes_test.tsx b/packages/fresh/src/fs_routes_test.tsx index ddb37b01..c9f980f0 100644 --- a/packages/fresh/src/fs_routes_test.tsx +++ b/packages/fresh/src/fs_routes_test.tsx @@ -14,6 +14,7 @@ import * as path from "@std/path"; async function createServer( files: Record>, + mountPath?: string, ): Promise { const fs = createFakeFs(files); @@ -26,7 +27,7 @@ async function createServer( }); const app = new App() - .fsRoutes(); + .fsRoutes(mountPath); const buildCache = new MockBuildCache(fsFiles, "development"); setBuildCache(app, buildCache, "development"); @@ -1639,3 +1640,24 @@ Deno.test("fsRoutes - ignores test files in routes folder", async () => { expect(rawFiles.some((f) => f.filePath.includes("baz.test.tsx"))).toBe(false); expect(rawFiles.some((f) => f.filePath.includes("qux_test.js"))).toBe(false); }); + +Deno.test("fsRoutes - pattern argument", async () => { + const server = await createServer({ + "routes/index.ts": { + handler: { + GET: () => new Response("ok"), + }, + }, + "routes/foo.ts": { + handler: { + GET: () => new Response("ok"), + }, + }, + }, "/mount"); + + let res = await server.get("/mount"); + expect(await res.text()).toEqual("ok"); + + res = await server.get("/mount/foo"); + expect(await res.text()).toEqual("ok"); +});