import Context from './context'; import * as file from './file'; import FilteredHttpCollection, { IFiltered } from './filtering/collection'; import { ComparatorFn } from './filtering/comparator'; import { ISerializedHttpPartialDeepMatch, MatchFn } from './filtering/matcher'; import { Redactor } from './filtering/redact'; import { ISerializedHttp } from './http-serializer'; import { IInterceptOptions } from './interceptor'; import Recording from './recording'; export declare type GenericTest = (...args: any) => Promise | void; export declare type GenericTestFunction = (title: string, fn: GenericTest) => any; export declare type HttpFilter = string | RegExp | ISerializedHttpPartialDeepMatch | MatchFn; export interface IRecordableTest { test?: GenericTestFunction; it?: GenericTestFunction; prefix?: string; dir: string; } /** * Options to configure intercept of HTTP requests */ export interface IYesNoInterceptingOptions extends IInterceptOptions { /** * Comparator function used to determine whether an intercepted request * matches a loaded mock. */ comparatorFn?: ComparatorFn; } /** * Client API for YesNo */ export declare class YesNo implements IFiltered { private readonly interceptor; private readonly ctx; constructor(ctx: Context); /** * Restore HTTP functionality */ restore(): void; /** * Spy on intercepted requests */ spy(options?: IYesNoInterceptingOptions): void; /** * Mock responses for intercepted requests * @todo Reset the request counter? */ mock(mocks: file.IHttpMock[], options?: IYesNoInterceptingOptions): void; /** * Start a new recording. * * Depending on the configured mode, will either spy on all outbound HTTP requests * or return mocks loaded from disc. * * When done, call the `complete()` on the returned recording * to save all intercepted requests to disc if applicable. * @param options Where to load/save mocks * @returns A new recording. */ recording(options: file.IFileOptions): Promise; /** * Create a test function that will wrap its provided test in a recording. */ test({ it, test, dir, prefix }: IRecordableTest): GenericTestFunction; /** * Load request/response mocks from disk */ load(options: file.IFileOptions): Promise; /** * Save intercepted requests * * @returns Full filename of saved JSON if generated */ save(options: file.ISaveOptions & file.IFileOptions): Promise; /** * Clear all stateful information about requests. * * If used in a test suite, this should be called after each test. */ clear(): void; /** * Create a filter collection * @todo Convert everything to a match fn * @param query */ matching(filter?: HttpFilter): FilteredHttpCollection; /** * Get all intercepted requests */ intercepted(): ISerializedHttp[]; /** * Get all loaded mocks */ mocks(): ISerializedHttp[]; /** * Redact property on all records */ redact(property: string | string[], redactor?: Redactor): void; private getModeByEnv; private getRecordsToSave; /** * Enable intercepting requests */ private enable; private setMocks; /** * Determine the current mode */ private isMode; private createInterceptor; private onIntercept; private onProxied; private setMode; private getCollection; private recordRequest; private recordResponse; }