first iteration of v.3 router
This commit is contained in:
22
router.test.ts
Executable file → Normal file
22
router.test.ts
Executable file → Normal file
@@ -80,7 +80,7 @@ describe("Router", () => {
|
||||
it("should execute global middleware", async () => {
|
||||
let middlewareExecuted = false;
|
||||
|
||||
router.use(async (_ctx, next) => {
|
||||
router.use(async (_, _ctx, next) => {
|
||||
middlewareExecuted = true;
|
||||
return await next();
|
||||
});
|
||||
@@ -99,9 +99,9 @@ describe("Router", () => {
|
||||
it("should execute path-specific middleware", async () => {
|
||||
let middlewareExecuted = false;
|
||||
|
||||
router.use("/test", async (_ctx, next) => {
|
||||
router.use("/test", async (_, _ctx, next) => {
|
||||
middlewareExecuted = true;
|
||||
console.log('middlware happened')
|
||||
console.log("middlware happened");
|
||||
return await next();
|
||||
});
|
||||
|
||||
@@ -119,7 +119,7 @@ describe("Router", () => {
|
||||
it("should handle middleware parameters", async () => {
|
||||
const capturedParams: Record<string, string | undefined> = {};
|
||||
|
||||
router.use("/:version/.*", async (ctx, next) => {
|
||||
router.use("/:version/.*", async (_, ctx, next) => {
|
||||
capturedParams.version = ctx.params.version;
|
||||
return await next();
|
||||
});
|
||||
@@ -138,12 +138,12 @@ describe("Router", () => {
|
||||
it("should execute middleware in correct order", async () => {
|
||||
const order: number[] = [];
|
||||
|
||||
router.use(async (_ctx, next) => {
|
||||
router.use(async (_, _ctx, next) => {
|
||||
order.push(1);
|
||||
return await next();
|
||||
});
|
||||
|
||||
router.use("/test", async (_ctx, next) => {
|
||||
router.use("/test", async (_, _ctx, next) => {
|
||||
order.push(2);
|
||||
return await next();
|
||||
});
|
||||
@@ -198,7 +198,7 @@ describe("Router", () => {
|
||||
const apiRouter = new Router();
|
||||
let middlewareExecuted = false;
|
||||
|
||||
apiRouter.use(async (_ctx, next) => {
|
||||
apiRouter.use(async (_, _ctx, next) => {
|
||||
middlewareExecuted = true;
|
||||
return await next();
|
||||
});
|
||||
@@ -219,7 +219,7 @@ describe("Router", () => {
|
||||
|
||||
describe("Context State", () => {
|
||||
it("should maintain state across middleware chain", async () => {
|
||||
router.use(async (ctx, next) => {
|
||||
router.use(async (_, ctx, next) => {
|
||||
ctx.state.test = "value";
|
||||
return await next();
|
||||
});
|
||||
@@ -274,11 +274,11 @@ describe("Router", () => {
|
||||
describe("HTTP Methods", () => {
|
||||
const methods = ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"];
|
||||
|
||||
methods.forEach(method => {
|
||||
methods.forEach((method) => {
|
||||
it(`should handle ${method} requests`, async () => {
|
||||
const route = router.route("/test");
|
||||
route[method.toLowerCase() as keyof typeof route](
|
||||
async () => new Response(method)
|
||||
async () => new Response(method),
|
||||
);
|
||||
|
||||
const req = new Request("http://localhost/test", {
|
||||
@@ -291,4 +291,4 @@ describe("Router", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user