erest
Version:
Easy to build api server depend on @leizm/web and express.
34 lines (33 loc) • 1.06 kB
TypeScript
/**
* @file API Test
* @author Yourtion Guo <yourtion@gmail.com>
*/
import type { SuperTest, Test } from "supertest";
import type ERest from "..";
import { TestAgent } from "../agent";
import { type ISupportMethds } from "../utils";
/** 测试Agent */
export type IAgent = Readonly<ISupportMethds<(path: string) => TestAgent>>;
export interface ITestSession extends IAgent {
/** 原始SuperTestAgent */
readonly $agent: SuperTest<Test>;
}
export default class IAPITest {
private erest;
private info;
private app;
private testPath;
private supertest?;
constructor(erestIns: ERest<unknown>, path: string);
get get(): (path: string) => TestAgent;
get post(): (path: string) => TestAgent;
get put(): (path: string) => TestAgent;
get delete(): (path: string) => TestAgent;
get patch(): (path: string) => TestAgent;
/** 创建测试会话 */
session(): ITestSession;
/** 根据请求方法和请求路径查找对应的API */
private findApi;
/** 生成测试方法 */
private buildTest;
}