forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnock.d.ts
164 lines (133 loc) · 6.14 KB
/
nock.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// Type definitions for nock v8.0.0
// Project: https://github.com/node-nock/nock
// Definitions by: bonnici <https://github.com/bonnici>, Horiuchi_H <https://github.com/horiuchi>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
declare module "nock" {
export = nock;
function nock(basePath: string | RegExp, options?: nock.Options): nock.Scope;
namespace nock {
export function cleanAll(): void;
export function activate(): void;
export function isActive(): boolean;
export function isDone(): boolean;
export function pendingMocks(): void;
export function removeInterceptor(interceptor: Interceptor | RequestOptions): boolean;
export function disableNetConnect(): void;
export function enableNetConnect(matcher?: string | RegExp): void;
export function load(path: string): Scope[];
export function loadDefs(path: string): NockDefinition[];
export function define(defs: NockDefinition[]): Scope[];
export var emitter: NodeJS.EventEmitter;
export var recorder: Recorder;
export function restore(): void;
export var back: NockBack;
type HttpHeaders = { [key: string]: string | { (req: any, res: any, body: string): any; }; };
type InterceptFunction = (
uri: string | RegExp | { (uri: string): boolean; },
requestBody?: string | RegExp | { (body: any): boolean; } | any
) => Interceptor;
export type ReplyCallback = (err: any, result: ReplyCallbackResult) => void;
type ReplyCallbackResult = string | [number, string | any] | [number, string | any, HttpHeaders] | any;
export interface Scope extends NodeJS.EventEmitter {
get: InterceptFunction;
post: InterceptFunction;
put: InterceptFunction;
head: InterceptFunction;
patch: InterceptFunction;
merge: InterceptFunction;
delete: InterceptFunction;
intercept: (
uri: string | RegExp | { (uri: string): boolean; },
method: string,
requestBody?: string | RegExp | { (body: any): boolean; } | any,
options?: Options
) => Interceptor;
defaultReplyHeaders(headers: HttpHeaders): this;
matchHeader(name: string, value: string | RegExp | { (value: string): boolean; }): this;
filteringPath(regex: RegExp, replace: string): this;
filteringPath(fn: (path: string) => string): this;
filteringRequestBody(regex: RegExp, replace: string): this;
filteringRequestBody(fn: (body: string) => string): this;
log(out: () => void): this;
persist(): this;
shouldPersist(): boolean;
replyContentLength(): this;
replyDate(d?: Date): this;
done(): void;
isDone(): boolean;
restore(): void;
pendingMocks(): string[];
}
export interface Interceptor {
query(params: boolean | { (querObject: any): boolean; } | any): this;
reply(responseCode: number, body?: string | any, headers?: HttpHeaders): Scope;
reply(responseCode: number, callback: (uri: string, body: string, cb?: ReplyCallback) => ReplyCallbackResult, headers?: HttpHeaders): Scope;
reply(callback: (uri: string, body: string, cb?: ReplyCallback) => ReplyCallbackResult, headers?: HttpHeaders): Scope;
replyWithError(errorMessage: string | any): Scope;
replyWithFile(responseCode: number, fileName: string, headers?: HttpHeaders): Scope;
basicAuth(options: { user: string; pass?: string; }): this;
times(newCounter: number): this;
once(): this;
twice(): this;
thrice(): this;
delay(opts: number | { head?: number; body?: number; }): this;
delayBody(timeMs: number): this;
delayConnection(timeMs: number): this;
getTotalDelay(): number;
socketDelay(timeMs: number): this;
}
export interface Options {
allowUnmocked?: boolean;
reqheaders?: { [key: string]: string | RegExp | { (headerValue: string): boolean; }; };
badheaders?: string[];
filteringScope?: { (scope: string): boolean; };
}
export interface RequestOptions {
proto?: string;
_https_?: boolean;
hostname?: string;
host?: string;
port?: number;
method?: string;
path?: string;
}
export interface Recorder {
rec(options?: boolean | RecorderOptions): void;
clear(): void;
play(): string[] | NockDefinition[];
}
export interface RecorderOptions {
dont_print?: boolean;
output_objects?: boolean;
enable_reqheaders_recording?: boolean;
logging?: (content: string) => void;
use_separator?: boolean;
}
export interface NockDefinition {
scope: string;
port?: number | string;
method?: string;
path: string;
body?: string | any;
status?: number;
response?: string | any;
headers?: HttpHeaders;
reqheaders?: { [key: string]: string | RegExp | { (headerValue: string): boolean; }; };
options?: Options;
}
export type NockBackMode = "wild" | "dryrun" | "record" | "lockdown";
export interface NockBack {
fixtures: string;
setMode(mode: NockBackMode): void;
(fixtureName: string, nockedFn: (nockDone: () => void) => void): void;
(fixtureName: string, options: NockBackOptions, nockedFn: (nockDone: () => void) => void): void;
}
export interface NockBackOptions {
before?: (def: NockDefinition) => void;
after?: (scope: Scope) => void;
afterRecord?: (defs: NockDefinition[]) => NockDefinition[];
recorder?: RecorderOptions;
}
}
}