This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtypes.ts
62 lines (52 loc) · 1.93 KB
/
types.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
/* eslint-disable @typescript-eslint/interface-name-prefix */
export type PluginBuilder<I, Args extends any[]> = (...args: Args) => Plugin<I>
import Nock = require('nock')
export interface Context {
test: (typeof it | typeof it.skip);
plugins: {[k: string]: PluginBuilder<any, any>};
expectation?: string;
chain: Plugin<any>[];
error?: Error & {code?: string};
retries?: number;
timeout?: number;
}
export interface Plugin<I> {
run?(context: I): any;
init?(context: I): any;
finally?(context: I): any;
catch?(context: I): any;
}
export interface PluginDef {
output: object | unknown;
args: any[];
}
export interface Plugins {[k: string]: PluginDef}
export interface ITestCallbackContext {
skip(): this;
timeout(ms: number | string): this;
retries(n: number): this;
slow(ms: number): this;
[index: string]: any;
}
export type MochaCallback<I> = (this: ITestCallbackContext, context: I, done: MochaDone) => any
export interface It<I> {
(expectation: string, cb?: MochaCallback<I>): void;
(cb?: MochaCallback<I>): void;
}
export type Base<I extends Context, T extends Plugins> = {
it: It<I>;
end: It<I>;
add<K extends string, O>(key: K, cb: ((context: I) => Promise<O> | O) | Promise<O> | O): Base<I & {[P in K]: O}, T>;
do<O>(cb: (context: I & O) => any): Base<O & I, T>;
finally(cb: (context: I) => any): Base<I, T>;
register<K extends string, O, A extends any[]>(key: K, plugin: (...args: A) => Plugin<O & I>): Base<I, T & {[P in K]: {output: O; args: A}}>;
} & {[P in keyof T]: (...args: T[P]['args']) => Base<T[P]['output'] & I, T>}
export interface EnvOptions {
clear?: boolean;
}
export type MochaDone = (err?: any) => void
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface NockScope extends Nock.Scope {}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface NockOptions extends Nock.Options {}
export type NockCallback = (nock: NockScope) => any