Options
All
  • Public
  • Public/Protected
  • All
Menu

mockttp

Index

References

Renames and re-exports HttpsOptions
Renames and re-exports HttpsPathOptions
Re-exports ForwardingOptions
Re-exports PassThroughLookupOptions
Renames and re-exports TlsRequest

Type Aliases

DnsLookupFunction: Omit<typeof dns.lookup, "__promisify__">
InitiatedRequest: Request
MaybePromise<T>: T | Promise<T>

Type Parameters

  • T

MockttpHttpsOptions: CAOptions & { defaultDomain?: string; tlsInterceptOnly?: { hostname: string }[]; tlsPassthrough?: { hostname: string }[] }
PEM: string | string[] | Buffer | Buffer[]
PortRange: { endPort: number; startPort: number }

Type declaration

  • endPort: number
  • startPort: number

A ProxyConfig is externally provided config that specifies a ProxySettingSource. It might be a ProxySettingSource itself, or it might include references to rule parameters, which must be dereferenced to make it usable as a ProxySettingSource.

ProxySettingCallback: ((params: ProxySettingCallbackParams) => MaybePromise<ProxySetting | undefined>)

Type declaration

ProxySettingCallbackParams: { hostname: string }

Type declaration

  • hostname: string
ProxySettingSource: ProxySetting | ProxySettingCallback | ProxySettingSource[] | undefined

A ProxySettingSource is a way to calculate the ProxySetting for a given request. It may be a fixed ProxySetting value, or a callback to get ProxySetting values, or an array of sources, which should be iterated to get the first usable value

RawHeaders: [key: string, value: string][]
RuleParameterReference<R>: { [MOCKTTP_PARAM_REF]: string }

A reference to a rule parameter defined in the ruleParameters admin server option of the corresponding admin server.

Rule parameter references are only valid with a remote client. They can be useful in cases where the admin server has access to local state or APIs that are not accessible from the remote client, but which would be useful in rule definitions. This is only supported for some specific parameters where documented explicitly in that rule parameter.

Type Parameters

  • R

Type declaration

  • [MOCKTTP_PARAM_REF]: string
RuleParameters: {}

Type declaration

  • [key: string]: unknown
Serialized<T>: { [ K in keyof T]: T[K] extends string | undefined ? string | undefined : T[K] extends unknown[] ? SerializedValue<T[K][0]>[] : SerializedValue<T[K]> }

Type Parameters

  • T

SerializedValue<T>: T & { topicId: string }

Type Parameters

  • T

SubscribableEvent: "request-initiated" | "request" | "response" | "websocket-request" | "websocket-accepted" | "websocket-message-received" | "websocket-message-sent" | "websocket-close" | "abort" | "tls-passthrough-opened" | "tls-passthrough-closed" | "tls-client-error" | "client-error" | "rule-event"
defaultMaxListeners: typeof defaultMaxListeners

Variables

DEFAULT_ADMIN_SERVER_PORT: 45454 = 45454
MOCKTTP_PARAM_REF: typeof MOCKTTP_PARAM_REF = ...

Functions

  • generateCACertificate(options?: { bits?: number; commonName?: string; countryName?: string; organizationName?: string }): Promise<{ cert: string; key: string }>
  • Generate a CA certificate for mocking HTTPS.

    Returns a promise, for an object with key and cert properties, containing the generated private key and certificate in PEM format.

    These can be saved to disk, and their paths passed as HTTPS options to a Mockttp server.

    Parameters

    • options: { bits?: number; commonName?: string; countryName?: string; organizationName?: string } = {}
      • Optional bits?: number
      • Optional commonName?: string
      • Optional countryName?: string
      • Optional organizationName?: string

    Returns Promise<{ cert: string; key: string }>

  • generateSPKIFingerprint(certPem: PEM): string
  • Get a Mockttp admin server, which can be used with a Mockttp remote client to create & manage Mockttp instances either from remote machines or from local environments that lack necessary capabilities, e.g. to use Mockttp from inside a browser.

    This function exists so you can set up these servers programmatically, but for most usage you can just run your tests via the mockttp binary, which will automatically start and stop an admin server for you:

    mockttp -c <your test command>
    

    Parameters

    Returns MockttpAdminServer

  • Get a Mockttp instance on the local machine.

    In most simple environments, you can call this method directly and immediately get a Mockttp instance and start mocking servers.

    In node, the mocked servers will run in process and require no further setup.

    In browsers this is an alias for getRemote. You'll need to start a Mockttp admin server outside your tests before calling this, which will create and manage your fake servers outside the browser.

    Parameters

    Returns Mockttp

  • Get a Mockttp instance, controlled through a Mockttp admin server.

    This connects to a Mockttp admin server, and uses that to start and stop mock servers.

    Parameters

    Returns Mockttp

  • Reset a remote admin server, shutting down all Mockttp servers controlled by that admin server. This is equivalent to calling client.stop() for all remote clients of the target server.

    This can be useful in some rare cases, where a client might fail to reliably tear down its own server, e.g. in Cypress testing. In this case, it's useful to reset the admin server completely remotely without needing access to any previous client instances, to ensure all servers from previous test runs have been shut down.

    After this is called, behaviour of any previously connected clients is undefined, and it's likely that they may throw errors or experience other undefined behaviour. Ensure that client.stop() has been called on all active clients before calling this method.

    Parameters

    Returns Promise<void>

Generated using TypeDoc