UNPKG

2.02 kBTypeScriptView Raw
1/// <reference types="mocha" />
2export declare type PluginBuilder<I, Args extends any[]> = (...args: Args) => Plugin<I>;
3import Nock = require('nock');
4export 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}
17export interface Plugin<I> {
18 run?(context: I): any;
19 init?(context: I): any;
20 finally?(context: I): any;
21 catch?(context: I): any;
22}
23export interface PluginDef {
24 output: object | unknown;
25 args: any[];
26}
27export interface Plugins {
28 [k: string]: PluginDef;
29}
30export 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}
37export declare type MochaCallback<I> = (this: ITestCallbackContext, context: I, done: MochaDone) => any;
38export interface It<I> {
39 (expectation: string, cb?: MochaCallback<I>): void;
40 (cb?: MochaCallback<I>): void;
41}
42export declare 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) => Promise<O> | O) | Promise<O> | 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};
59export interface EnvOptions {
60 clear?: boolean;
61}
62export declare type MochaDone = (err?: any) => void;
63export interface NockScope extends Nock.Scope {
64}
65export interface NockOptions extends Nock.Options {
66}
67export declare type NockCallback = (nock: NockScope) => any;