1 |
|
2 | export type PluginBuilder<I, Args extends any[]> = (...args: Args) => Plugin<I>;
|
3 | import Nock = require('nock');
|
4 | export interface Context {
|
5 | test: (typeof it | typeof it.skip);
|
6 | plugins: {
|
7 | [k: string]: PluginBuilder<any, any>;
|
8 | };
|
9 | expectation?: string;
|
10 | chain: Plugin<any>[];
|
11 | error?: Error & {
|
12 | code?: string;
|
13 | };
|
14 | retries?: number;
|
15 | timeout?: number;
|
16 | }
|
17 | export interface Plugin<I> {
|
18 | run?(context: I): any;
|
19 | init?(context: I): any;
|
20 | finally?(context: I): any;
|
21 | catch?(context: I): any;
|
22 | }
|
23 | export interface PluginDef {
|
24 | output: Record<string, unknown> | unknown;
|
25 | args: any[];
|
26 | }
|
27 | export interface Plugins {
|
28 | [k: string]: PluginDef;
|
29 | }
|
30 | export interface ITestCallbackContext {
|
31 | skip(): this;
|
32 | timeout(ms: number | string): this;
|
33 | retries(n: number): this;
|
34 | slow(ms: number): this;
|
35 | [index: string]: any;
|
36 | }
|
37 | export type MochaCallback<I> = (this: ITestCallbackContext, context: I, done: MochaDone) => any;
|
38 | export interface It<I> {
|
39 | (expectation: string, cb?: MochaCallback<I>): void;
|
40 | (cb?: MochaCallback<I>): void;
|
41 | }
|
42 | export type Base<I extends Context, T extends Plugins> = {
|
43 | it: It<I>;
|
44 | end: It<I>;
|
45 | add<K extends string, O>(key: K, cb: ((context: I) => O | Promise<O>) | O | Promise<O>): Base<I & {
|
46 | [P in K]: O;
|
47 | }, T>;
|
48 | do<O>(cb: (context: I & O) => any): Base<O & I, T>;
|
49 | finally(cb: (context: I) => any): Base<I, T>;
|
50 | register<K extends string, O, A extends any[]>(key: K, plugin: (...args: A) => Plugin<O & I>): Base<I, T & {
|
51 | [P in K]: {
|
52 | output: O;
|
53 | args: A;
|
54 | };
|
55 | }>;
|
56 | } & {
|
57 | [P in keyof T]: (...args: T[P]['args']) => Base<T[P]['output'] & I, T>;
|
58 | };
|
59 | export interface EnvOptions {
|
60 | clear?: boolean;
|
61 | }
|
62 | export type MochaDone = (err?: any) => void;
|
63 | export interface NockScope extends Nock.Scope {
|
64 | }
|
65 | export interface NockOptions extends Nock.Options {
|
66 | }
|
67 | export type NockCallback = (nock: NockScope) => any;
|