feat: add support for route groups (#1563)

This commit is contained in:
Marvin Hagemeister
2023-08-02 09:51:20 +02:00
committed by GitHub
parent 4b28e2e269
commit e4d797ae4e
17 changed files with 384 additions and 218 deletions
+1 -28
View File
@@ -1,32 +1,5 @@
import { assertEquals, assertThrows } from "$std/testing/asserts.ts";
import { assert } from "../../tests/deps.ts";
import {
middlewarePathToPattern,
pathToPattern,
selectMiddlewares,
} from "./context.ts";
import { MiddlewareRoute } from "./types.ts";
Deno.test("selectMiddlewares", () => {
const url = "https://fresh.deno.dev/api/abc/def";
const middlewaresPath = [
// should select
"_middleware",
"api/_middleware",
"api/[id]/_middleware",
"api/[id]/[path]/_middleware",
// should not select
"api/xyz/_middleware",
"api/[id]/xyz/_middleware",
"api/[id]/[path]/foo/_middleware",
];
const mwRoutes = middlewaresPath.map((path) =>
middlewarePathToPattern(path)
) as MiddlewareRoute[];
const mws = selectMiddlewares(url, mwRoutes);
assert(mws.length === 4);
});
import { pathToPattern } from "./context.ts";
Deno.test("pathToPattern", async (t) => {
await t.step("creates pattern", () => {