From 8c0aee775ecccee7c0d06035576804f2e240eb33 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Tue, 2 Jul 2024 14:55:02 +0800 Subject: [PATCH] fix: export mockHttpClient types --- index.d.ts | 19 ++++++++++--------- index.test-d.ts | 7 +++++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/index.d.ts b/index.d.ts index 9dd63ef..a59fdf5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -5,14 +5,15 @@ import { MockAgent } from 'urllib'; import { Suite } from 'mocha'; export { MockAgent }; -interface EggTest extends Test { + +export interface EggTest extends Test { unexpectHeader(name: string, b?: Function): EggTest; expectHeader(name: string, b?: Function): EggTest; } -type Methods = 'get' | 'post' | 'delete' | 'del' | 'put' | 'head' | 'options' | 'patch' | 'trace' | 'connect'; +export type Methods = 'get' | 'post' | 'delete' | 'del' | 'put' | 'head' | 'options' | 'patch' | 'trace' | 'connect'; -export interface BaseMockApplication extends Application { // tslint:disble-line +export interface BaseMockApplication extends Application { ready(): Promise; close(): Promise; callback(): any; @@ -81,8 +82,8 @@ export interface BaseMockApplication extends Application { // tslint:disbl backgroundTasksFinished(): Promise; } -interface ResultObject { - data?: string | object; +export interface ResultObject { + data?: string | object | Buffer; status?: number; headers?: any; delay?: number; @@ -90,9 +91,9 @@ interface ResultObject { repeats?: number; } -type ResultFunction = (url?: string, opts?: any) => ResultObject | string | void; +export type ResultFunction = (url?: string, opts?: any) => ResultObject | string | void; -type MockHttpClientResult = ResultObject | ResultFunction | string; +export type MockHttpClientResult = ResultObject | ResultFunction | string; export interface MockOption { /** @@ -126,8 +127,8 @@ export interface MockOption { clean?: boolean; } -type EnvType = 'default' | 'test' | 'prod' | 'local' | 'unittest' | string & {}; -type LogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'NONE'; +export type EnvType = 'default' | 'test' | 'prod' | 'local' | 'unittest' | string & {}; +export type LogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'NONE'; export interface MockApplication extends BaseMockApplication { } diff --git a/index.test-d.ts b/index.test-d.ts index dea9839..05df01b 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,6 +1,6 @@ import { expectType } from 'tsd'; import { Application, Context } from 'egg'; -import { MockApplication, MockAgent } from '.'; +import { MockApplication, MockAgent, ResultObject } from '.'; import { app, mock, mm } from './bootstrap'; expectType(app); @@ -41,4 +41,7 @@ expectType>(app.mockRestore()); expectType>(app.mockContextScope(async () => {})); expectType>(app.mockContextScope(async (ctx) => {})); -expectType>(app.backgroundTasksFinished()); \ No newline at end of file +expectType>(app.backgroundTasksFinished()); + +const result: ResultObject = {}; +expectType(result.status!);