aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/filesystem_router.test.ts
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-11-22 02:25:58 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-11-22 02:25:58 -0800
commit15a5aa1a682c81cb017795e9489dbb279e7b6717 (patch)
tree1d5b60e2732f1ba4225a42e2cbaa0c1cac0619ce /test/bun.js/filesystem_router.test.ts
parent3cf229a89824d8d0820724c14c3839cd6ac39940 (diff)
downloadbun-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.ts26
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`);
+});