From 15a5aa1a682c81cb017795e9489dbb279e7b6717 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Tue, 22 Nov 2022 02:25:58 -0800 Subject: Update filesystem_router.test.ts --- test/bun.js/filesystem_router.test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/bun.js/filesystem_router.test.ts') diff --git a/test/bun.js/filesystem_router.test.ts b/test/bun.js/filesystem_router.test.ts index c375cbb22..9aba52a30 100644 --- a/test/bun.js/filesystem_router.test.ts +++ b/test/bun.js/filesystem_router.test.ts @@ -83,3 +83,29 @@ it("should find files", () => { expect(router.match("/b").name).toBe("/b"); expect(router.match("/abc/123").params.id).toBe("123"); }); + +it("should support dynamic routes", () => { + // set up the test + const tempdir = realpathSync(tmpdir()) + "/"; + rmSync(tempdir + "fs-router-test-02", { recursive: true, force: true }); + createTree(tempdir + "fs-router-test-02", [ + "index.tsx", + "posts/[id].tsx", + "posts.tsx", + ]); + + const router = new Bun.FileSystemRouter({ + dir: tempdir + "fs-router-test-02/", + style: "nextjs", + }); + + const { + name, + params: { id }, + filePath, + } = router.match("/posts/hello-world"); + + expect(id).toBe("hello-world"); + expect(name).toBe("/posts/[id]"); + expect(filePath).toBe(`${tempdir}fs-router-test-02/posts/[id].tsx`); +}); -- cgit v1.2.3