diff options
author | 2022-11-22 02:25:58 -0800 | |
---|---|---|
committer | 2022-11-22 02:25:58 -0800 | |
commit | 15a5aa1a682c81cb017795e9489dbb279e7b6717 (patch) | |
tree | 1d5b60e2732f1ba4225a42e2cbaa0c1cac0619ce /test/bun.js/filesystem_router.test.ts | |
parent | 3cf229a89824d8d0820724c14c3839cd6ac39940 (diff) | |
download | bun-15a5aa1a682c81cb017795e9489dbb279e7b6717.tar.gz bun-15a5aa1a682c81cb017795e9489dbb279e7b6717.tar.zst bun-15a5aa1a682c81cb017795e9489dbb279e7b6717.zip |
Update filesystem_router.test.ts
Diffstat (limited to 'test/bun.js/filesystem_router.test.ts')
-rw-r--r-- | test/bun.js/filesystem_router.test.ts | 26 |
1 files changed, 26 insertions, 0 deletions
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`); +}); |