Skip to content

Commit

Permalink
Fix types in Router test
Browse files Browse the repository at this point in the history
  • Loading branch information
opl- committed Sep 18, 2024
1 parent edfc1c1 commit 98c8935
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions test/Router.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import test from 'ava';
import {Context, Middleware, Next} from 'koa';
import {ParameterizedContext, Middleware as KoaMiddleware, Next} from 'koa';

import {Router, SpecialMethod, TERMINATOR_MIDDLEWARE_KEY} from '../lib/Router';
import {Router, RouterContext, SpecialMethod, TERMINATOR_MIDDLEWARE_KEY} from '../lib/Router';
import {StagedArray} from '../lib/StagedArray';

let router = new Router();

type Context = ParameterizedContext<{}, RouterContext<{}, {params: Record<string, any>;}>, string | undefined>;
type Middleware = KoaMiddleware<{}, Context>;

type MethodsWithHelpers = 'CONNECT' | 'DELETE' | 'GET' | 'HEAD' | 'OPTIONS' | 'PATCH' | 'POST' | 'PUT' | 'TRACE';

async function doSimulation(method: MethodsWithHelpers, path: string, nextMiddleware: Middleware): Promise<Context> {
Expand All @@ -23,7 +26,7 @@ async function doSimulation(method: MethodsWithHelpers, path: string, nextMiddle
return context as any;
}

async function simulate(method: MethodsWithHelpers, path: string, shouldMatch = true, modifyOutput?: (context: any) => any): Promise<string | {message: string; body?: string;} | undefined> {
async function simulate(method: MethodsWithHelpers, path: string, shouldMatch = true, modifyOutput?: (context: Context) => any): Promise<string | {message: string; body?: string;} | undefined> {
let matched = true;

const context = await doSimulation(method, path, async () => {
Expand Down

0 comments on commit 98c8935

Please sign in to comment.