UNPKG

nock

Version:

HTTP server mocking and expectations library for Node.js

45 lines (44 loc) • 1.75 kB
import type { Scope } from './scope.ts'; import type { Definition } from './scope.ts'; import type { RecorderOptions } from './recorder.ts'; export type BackMode = 'wild' | 'dryrun' | 'record' | 'update' | 'lockdown'; export interface BackOptions { before?: (def: Definition) => void; after?: (scope: Scope) => void; afterRecord?: (defs: Definition[]) => Definition[] | string; recorder?: RecorderOptions; } declare namespace Back { let fixtures: string | null; let currentMode: string; } declare function Back(fixtureName: string, nockedFn: (nockDone: () => void) => void): void; declare function Back(fixtureName: string, options: BackOptions, nockedFn: (nockDone: () => void) => void): void; declare function Back(fixtureName: string, options?: BackOptions): Promise<{ nockDone: () => void; context: BackContext; }>; declare namespace Back { var setMode: (mode: string) => void; } declare function load(fixture?: string, options?: BackOptions | Record<string, any>): { isLoaded: boolean; isRecording: boolean; scopes: Scope[]; assertScopesFinished: () => void; query: () => { method: string; uri: string | RegExp | ((path: string) => boolean); basePath: string | RegExp; path: string | RegExp | ((path: string) => boolean); queries: boolean | Record<string, any> | ((queryObject: Record<string, any>) => boolean) | null; counter: number; body: any; statusCode: number | null | undefined; optional: boolean; }[]; }; export type BackContext = Omit<ReturnType<typeof load>, 'isRecording'>; export type InterceptorSurface = ReturnType<BackContext['query']>[number]; export type Back = typeof Back; export default Back;