UNPKG

http-request-mock

Version:

Intercept & mock http requests issued by XMLHttpRequest, fetch, nodejs https/http module, axios, jquery, superagent, ky, node-fetch, request, got or any other request libraries by intercepting XMLHttpRequest, fetch and nodejs native requests in low level.

80 lines (79 loc) 2.44 kB
export const entryPoints: string[]; export const defaultHeadersForProxyServer: { 'x-powered-by': string; 'access-control-allow-origin': string; 'access-control-allow-methods': string; 'access-control-allow-headers': string; 'access-control-expose-headers': string; 'access-control-allow-credentials': string; }; /** * Common log * @param {...any} args */ export function log(...args: any[]): void; /** * Try to parse a JSON string * @param {unknown} body */ export function tryToParseJson(str: any, defaultVal?: null): any; /** * Set a global localStorage object for the compatibility of cache plugin. */ export function setLocalStorage(): void; /** * Reload .runtime.js and the specified mock files. * @param {string} mockDirectory * @param {string[]} files */ export function reloadRuntime(mockDirectory: string, files?: string[]): void; /** * Get root directory of current application */ export function getAppRoot(): string; /** * Resolve path but treat '\' as '/' on windows * @param {any} args */ export function resolve(...args: any): string; /** * Treat '\' as '/' on windows * @param {string} path * @returns */ export function formatPath(path: string): string; /** * Watch mock directory & update .runtime.js. * @param {object} webpackInstance * @param {string} mockDirectory * @param {function} reloadFunction */ export function watchDir(webpackInstance: object, mockDirectory: string, reloadFunction: Function): void; /** * Generate a stream transform for response. * @param {object} response * @param {function | undefined} handler */ export function responseTransform(response: object, handler: Function | undefined): Transform; /** * Get body for the specified request. * @param {object} request */ export function getRequestBody(request: object): Promise<any> | undefined; /** * Parse search query. * @param {object|string} search */ export function parseQuery(search: object | string): any; /** * Proxy the received request to the specified url. * The specified url is with protocol such as: http://jsonplaceholder.typicode.com/todos/1 * @param {object} proxyInstance node-http-proxy instance * @param {object} req * @param {object} res * @param {string} url * @param {function | undefined} handler * @returns */ export function doProxy({ proxyInstance, req, res, url, handler, headers }: object): Promise<any>; import { Transform } from "stream";