/** * @file API Agent * @author Yourtion Guo */ import type { IDebugger } from "debug"; import type { Test } from "supertest"; import type ERest from "."; import { type SUPPORT_METHODS } from "./api"; import type { SourceResult } from "./utils"; export interface ITestAgentOption { erest: ERest; sourceFile: SourceResult; method: SUPPORT_METHODS; path: string; agent?: Test; takeExample: boolean; agentTestName?: string; headers?: Record; input?: Record; output?: Record; agentHeader?: Record; agentInput: Record; agentOutput?: Record; } /** * 测试代理类 */ export declare class TestAgent { options: ITestAgentOption; key: string; debug: IDebugger; /** * 构造函数 * * @param method HTTP请求方法 * @param path 请求路径 * @param key 键名:`method path` * @param sourceFile 源文件路径描述对象 * @param erestIns hojs实例 */ constructor(method: SUPPORT_METHODS, path: string, key: string, sourceFile: SourceResult, erestIns: ERest); /** 设置`supertest.Agent`实例 */ setAgent(agent: Test): void; /** 初始化`supertest.Agent`实例 */ initAgent(app: unknown): void; /** 获取测试代理 */ agent(): TestAgent; /** 对测试结果加入文档 */ takeExample(name: string): this; /** 设置请求header */ headers(data: Record): this; /** 添加 query 参数 */ query(data: Record): this; /** 添加输入参数 */ input(data: Record): this; /** 添加 POST 参数 */ attach(data: Record): this; /** 保存输出结果到 Example */ private saveExample; /** 获取输出结果 */ private output; /** 期望输出成功结果 */ success(): Promise | undefined; /** 期望输出失败结果 */ error(): Promise | undefined; /** 获取原始输出 */ raw(): Promise | undefined; }