Skip to content

Commit

Permalink
fix: export mockHttpClient types
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Jul 2, 2024
1 parent 5cfd286 commit 8c0aee7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
19 changes: 10 additions & 9 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, C> extends Application { // tslint:disble-line
export interface BaseMockApplication<T, C> extends Application {
ready(): Promise<void>;
close(): Promise<void>;
callback(): any;
Expand Down Expand Up @@ -81,18 +82,18 @@ export interface BaseMockApplication<T, C> extends Application { // tslint:disbl
backgroundTasksFinished(): Promise<void>;
}

interface ResultObject {
data?: string | object;
export interface ResultObject {
data?: string | object | Buffer;
status?: number;
headers?: any;
delay?: number;
persist?: boolean;
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 {
/**
Expand Down Expand Up @@ -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<Application, Context> { }

Expand Down
7 changes: 5 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -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<MockApplication>(app);
Expand Down Expand Up @@ -41,4 +41,7 @@ expectType<Promise<void>>(app.mockRestore());
expectType<Promise<void>>(app.mockContextScope(async () => {}));
expectType<Promise<void>>(app.mockContextScope(async (ctx) => {}));

expectType<Promise<void>>(app.backgroundTasksFinished());
expectType<Promise<void>>(app.backgroundTasksFinished());

const result: ResultObject = {};
expectType<number>(result.status!);

0 comments on commit 8c0aee7

Please sign in to comment.