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.

90 lines (89 loc) 3.67 kB
export = HttpRequestMockMockPlugin; declare class HttpRequestMockMockPlugin { /** * http-request-mock parameters * * @param {regexp} entry Required, entry file into which mock dependencies will be injected. * @param {string} dir Required, mock directory which contains all mock files & the runtime mock config entry file. * @param {function} watch Optional, callback when some mock file is changed. * @param {boolean} enable Optional, whether or not to enable this plugin. Default value depends: NODE_ENV. * The default value will depend on your environment variable NODE_ENV if not specified: * i.e.: It'll be true on a development environment(NODE_ENV=development) by default. * @param {string} type Optional, the module type of .runtime.js.. Defaults to 'cjs'. * Valid values are: es6(alias of ESM), cjs(alias of commonjs). * * @param {string} index Optional, Index entry, automatic detection by default. * Valid values are: * [src/index.js] for commonJS * [http-request-mock.js] for UMD * [http-request-mock.pure.js] An alternative version without faker and cache plugins for UMD. * [http-request-mock.esm.mjs] for ESM * [http-request-mock.pure.esm.mjs] for ESM An alternative version without faker and cache plugins for ESM. * * @param {string} proxyMode Optional, proxy mode. In proxy mode, http-request-mock will use a proxy server to * receive incoming requests. Mock files will be run in a node environment. * [matched] Proxy requests which are matched your defined mock items. * [middleware] For the middleware plugin. (default: "none") */ constructor({ entry, dir, watch, enable, type, index, proxyMode, }: regexp); dir: string; entry: RegExp; watch: regexp; enable: boolean; type: any; getIndexEntry: string; environment: string; proxyServer: string; proxyMode: any; runtimeFile: string; /** * Initialize webpack plugin & inject dependencies into entry. * * @param {Webpack Compiler Object} compiler */ apply(compiler: any): void; /** * Initialize proxy server in a proxy mode. */ initProxyServer(): Promise<void>; /** * Inject mock config file into entry by webpack config entry. * @param {Webpack Compiler Object} compiler */ injectMockConfigFileIntoEntryByWebpackConfigEntry(compiler: any): void; /** * Use regexp to test against path which treats '\' as '/' on windows. * * @param {RegExp} regexp * @param {string} path */ testPath(regexp: RegExp, path: string): boolean; /** * Set watch callback if specified. * @param {Webpack Compiler Object} compiler */ setWatchCallback(compiler: any): void; /** * Add mock dependencies dir or files to webpack context. * @param {Webpack Compiler Object} compiler */ addMockDependenciesToContext(compiler: any): void; /** * Get changed files in the mock directory. * @param {Webpack Compiler Object} compiler */ getChangedFiles(compiler: any): string[]; /** * Get all files in the mock directory. * @param {array} level */ getAllMockFiles(level?: array): any; /** * Get mock config file entry. */ setRuntimeConfigFile(): string; /** * Get mock config file entry content codes. */ getRuntimeFileContent(): any[]; }