fix: .fsRoutes() pattern argument not working (#3571)
Fixes https://github.com/denoland/fresh/issues/3566
This commit is contained in:
@@ -357,7 +357,8 @@ function applyCommandsInner<State>(
|
||||
}
|
||||
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:
|
||||
|
||||
@@ -14,6 +14,7 @@ import * as path from "@std/path";
|
||||
|
||||
async function createServer<T>(
|
||||
files: Record<string, string | Uint8Array | FreshFsMod<T>>,
|
||||
mountPath?: string,
|
||||
): Promise<FakeServer> {
|
||||
const fs = createFakeFs(files);
|
||||
|
||||
@@ -26,7 +27,7 @@ async function createServer<T>(
|
||||
});
|
||||
|
||||
const app = new App<T>()
|
||||
.fsRoutes();
|
||||
.fsRoutes(mountPath);
|
||||
|
||||
const buildCache = new MockBuildCache<T>(fsFiles, "development");
|
||||
setBuildCache<T>(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");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user