UNPKG

mockttp

Version:

Mock HTTP server for testing HTTP clients and stubbing webservices

77 lines 3.6 kB
import { MockedEndpoint } from "../types"; import { Mockttp, AbstractMockttp, MockttpOptions, PortRange, SubscribableEvent } from "../mockttp"; import type { RequestRuleData } from "../rules/requests/request-rule"; import type { WebSocketRuleData } from '../rules/websockets/websocket-rule'; import { AdminClientEvent } from './admin-client'; export interface MockttpClientOptions extends MockttpOptions { /** * The full URL to use to connect to a Mockttp admin server when using a * remote (or local but browser) client. * * When using a local server, this option is ignored. */ adminServerUrl?: string; /** * Options to include on all client requests, e.g. to add extra * headers for authentication. */ client?: { headers?: { [key: string]: string; }; }; /** * Where should message body decoding happen? If set to 'server-side', * (the default) then the request body will be pre-decoded on the server, * and delivered to the client in decoded form (in addition to its * encoded form), meaning that the client doesn't need to do any * decoding itself (which can be awkward e.g. given encodings like * zstd/Brotli with poor browser JS support). * * If set to 'none', the request body will be delivered to * the client in original encoded form. If so, any access to data * that requires decoding (e.g. `response.body.getText()` on a * gzipped response) will fail. Instead, you will need to read and * decode `body.buffer` manually yourself. * * This is only relevant for advanced use cases. In general, you * should leave this as 'server-side' for convenient reliable * behaviour, and set it only to 'none' if you are handling * decoding yourself and want to actively optimize for that. */ messageBodyDecoding?: 'server-side' | 'none'; } export type MockttpClientEvent = `admin-client:${AdminClientEvent}`; /** * A Mockttp implementation, controlling a remote Mockttp admin server. * * A MockttpClient supports the exact same Mockttp API as MockttpServer, but rather * than directly using Node.js APIs to start a mock server and rewrite traffic, it * makes calls to a remote admin server to start a mock server and rewrite traffic * there. This is useful to allow proxy configuration from inside browser tests, and * to allow creating mock proxies that run on remote machines. */ export declare class MockttpClient extends AbstractMockttp implements Mockttp { private mockServerOptions; private messageBodyDecoding; private adminClient; private requestBuilder; constructor(options?: MockttpClientOptions); enableDebug(): Promise<void>; reset: () => Promise<void>; get url(): string; get port(): number; start(port?: number | PortRange): Promise<void>; stop(): Promise<void>; addRequestRules: (...rules: RequestRuleData[]) => Promise<MockedEndpoint[]>; setRequestRules: (...rules: RequestRuleData[]) => Promise<MockedEndpoint[]>; addWebSocketRules: (...rules: WebSocketRuleData[]) => Promise<MockedEndpoint[]>; setWebSocketRules: (...rules: WebSocketRuleData[]) => Promise<MockedEndpoint[]>; private _addRequestRules; private _addWsRules; getMockedEndpoints(): Promise<MockedEndpoint[]>; getPendingEndpoints(): Promise<MockedEndpoint[]>; getRuleParameterKeys(): Promise<string[]>; on(event: SubscribableEvent | MockttpClientEvent, callback: (data: any) => void): Promise<void>; } //# sourceMappingURL=mockttp-client.d.ts.map