Readonly
checksumContent produced by the last call to the checksum method, as it was passed to the hash algorithm.
Readonly
defaultUsed only when the mocks format is 'folder', specifies the default local path of the mock, relative to mocksFolder, . It uses the URL pathname to build an equivalent folders hierarchy, and appends the HTTP method as a leaf folder.
Optional
Readonly
defaultUsed only when the mocks format is 'har', specifies the default mock har key to use in case setMockHarKey is not called with a non-null value. It is computed by calling the mocks har key manager with the current request.
Note that it is lazily computed, but once computed, it is not re-computed even if mocksHarKeyManager changes.
Readonly
delayThe currently computed delay that will be applied, configured either by a call to setDelay,
or by the global setting. Note that if the delay is set to recorded
and the local mock
to use is not yet loaded, the value returned by this getter will be the default delay and not the recorded delay.
Readonly
harUsed only when the mocks format is 'har', specifies a list of mime types that will attempt to parse the request/response body as JSON. This will only be applicable to request bodies if saveInputRequestBody is set to true Default value will be [] and will only be overridden by setHarMimeTypesParseJson
Readonly
localUsed only when the mocks format is 'folder', specifies the local path of the mock, relative to mocksFolder. It is either the one set by the user through setLocalPath or defaultLocalPath.
Readonly
mockUsed only when the mocks format is 'folder', specifies the full, absolute path of the mock, built from localPath/defaultLocalPath, mocksFolder and possibly options.root if mocksFolder is not absolute.
Optional
Readonly
mockUsed only when the mocks format is 'har', specifies the key to use inside the har file to either read or write a mock.
The way the key is stored inside the har file depends on the value of mocksHarKeyManager.
Readonly
mocksUsed only when the mocks format is 'folder', specifies the root folder of all mocks, from which specific mocks paths will be resolved (resolved against options.root).
Readonly
mocksThe mocks format used for this request.
Readonly
mocksUsed only when the mocks format is 'har', contains the full path of the the har file to use.
If the file name has the .yml
or .yaml
extension, the YAML format is used instead of the standard JSON format to read and write the file.
Readonly
mocksUsed only when the mocks format is 'har', specifies the har key manager to use.
Readonly
modeThe current mode, configured either by a call to setMode, or by the global setting.
Readonly
optionsLink to global configuration options
Readonly
remoteURLThe current remote URL, configured either by a call to setRemoteURL, or by the global setting.
Readonly
requestThe wrapper around the input request
Readonly
responseThe wrapper around the output response
Readonly
saveWhether to save the content used to create a checksum when creating a new mock with a checksum for this request.
Readonly
saveWhether to save detailed timings when creating a new mock for this request.
Readonly
saveWhether to save the forwarded request body when creating a new mock for this request.
Readonly
saveWhether to save the forwarded request data (headers, method, URL) when creating a new mock for this request.
Readonly
saveWhether to save the content of the input request body when creating a new mock for this request.
Readonly
saveWhether to save the input request data (headers, method, URL) when creating a new mock for this request.
As soon as response is filled with a payload, this property holds the reference to that
payload's wrapper. The wrapper is useful here to know where the payload comes from.
Before that, this property is undefined
.
Compute a checksum using content from the request.
specifies which data from the request to include in the checksum
The actual checksum value, that you can then use for instance to add to the mock's path.
The computed checksum is intended to be added to the path of the mock so that semantically different requests use different mocks.
It is difficult to predict what will actually be relevant to include in the checksum or not for your use case, and that's why we provide many options to include/exclude/transform data (cf ChecksumArgs).
Note that we designed the API so that it is usually not needed to call the checksum method more than once for a given request/mock.
The method stores the computed content (which is passed to the hash
algorithm) in property checksumContent
(in the mock
object), as a string. It is built according to your options
and the request's data. It is also persisted, so that you can debug more easily,
especially by committing it into your SCM to analyze changes across versions of
your code. File is along with the other files of the mock under file name checksum
.
Create a wrapped payload (with user
origin) from the given payload data.
payload data
Combines fetchPayload and persistPayload and returns the wrapped payload.
Forward the client request to the remote backend and get a wrapped payload from the response in output.
Use data present in given wrapped payload to fill in the response.
payload to use to fill the response.
This method changes sourcePayload. It does nothing if sourcePayload is already set.
Depending on the mode, gets the payload (remote / local / default)
and uses fillResponseFromPayload with that payload.
If mode is manual
, does nothing.
Returns true if the mock exists locally.
Use IMock.hasLocalMock instead.
hasNoLocalFiles returns the opposite boolean value.
Returns true if the mock exists locally.
hasNoLocalMock returns the opposite boolean value.
Returns true if the mock does not exist locally.
Use IMock.hasNoLocalMock instead.
hasLocalFiles returns the opposite boolean value.
Returns true if the mock does not exist locally.
hasLocalMock returns the opposite boolean value.
Take the given wrapped payload and persist it in local files.
payload to persist in local files
Combines getPayloadAndFillResponse and sendResponse.
If mode is manual
, this method does nothing.
It also uses a private guard to make sure it is executed only once.
Therefore, if you call it from the hook method, the automatic call made for you after the
hook execution will actually not do anything (and the same if you call it yourself multiple times).
Returns a wrapped payload built from data persisted in local files.
If no local file is present, returns undefined
.
Combines readLocalPayload and fillResponseFromPayload if there is a
local payload then returns true
, otherwise does nothing and return false
.
Returns the wrapped local payload using readLocalPayload if it exists, otherwise use downloadPayload and returns this wrapped payload.
Returns the wrapped local payload using readLocalPayload if it exists, otherwise use fetchPayload and returns this wrapped payload.
Sets the delay that will be used to send the response to the client when the data is taken from the local mock.
can be either a number (to directly specify the delay in milliseconds),
'recorded'
(to read the delay from the time property of an already recorded mock if any)
or null
(to remove the effect of any previous call of setDelay
and use the default value from the global setting instead).
Sets the harMimeTypesParseJson value.
The mime types that should attempt to parse the body as json
Sets the localPath value.
Any combination of values and array of values, which will eventually all be flattened, converted to strings and joined to build a path.
The following example will use the HTTP method followed by the URL pathname:
mock.setLocalPath([mock.request.method, mock.request.pathname])
The following example will concatenate prefix
, all portions of the
URL pathname except the first one (also excluding the very first one which is empty since IFetchedRequest.pathname has a leading slash)
and optionally a suffix sequence depending on a boolean.
mock.setLocalPath([prefix, mock.request.pathname.split('/').slice(2), addSuffix ? [suffix, '-static-suffix'] : null])
Sets the mockHarKey value.
specifies the key to use inside the har file to either read or write a mock. If an array is set (which can be nested), it is flattened with null items removed, and joined with forward slashes to produce a string. Passing null resets the value to the default value.
Sets the mocksFolder value.
any combination of arrays of path parts, (as it is also possible for setLocalPath). You can pass an absolute path, or a relative one which will be resolved against options.root. Passing null resets the value to the default coming from the global setting.
Sets the mocksFormat value.
the mocks format to use for this request. Passing null resets the value to the default coming from the global setting.
Sets the mocksHarFile value.
any combination of arrays of path parts. You can pass an absolute path, or a relative one which will be resolved against options.root. Passing null resets the value to the default coming from the global setting.
Sets the mocksHarKeyManager value.
the har key manager to use for this request. Passing null resets the value to the default coming from the global setting.
Sets the mode for the current request.
mode to set, or null to use the default value from the global setting
Sets the current local payload, with a custom one you would have created.
payload to set
Sets the remote URL for the current request.
the URL to set, or null to use the default value from the global setting
Sets the saveChecksumContent value.
whether to save the content used to create a checksum when creating a new mock with a checksum for this request. Passing null resets the value to the default coming from the global setting.
Sets the saveDetailedTimings value.
whether to save detailed timings when creating a new mock with a checksum for this request. Passing null resets the value to the default coming from the global setting.
Sets the saveForwardedRequestBody value.
whether to save the forwarded request body when creating a new mock for this request. Passing null resets the value to the default coming from the global setting.
Sets the saveForwardedRequestData value.
whether to save the forwarded request data (headers, method, URL) when creating a new mock for this request. Passing null resets the value to the default coming from the global setting.
Sets the saveInputRequestBody value.
whether to save the content of the input request body when creating a new mock for this request. Passing null resets the value to the default coming from the global setting.
Sets the saveInputRequestData value.
whether to save the input request data (headers, method, URL) when creating a new mock for this request. Passing null resets the value to the default coming from the global setting.
The public interface exposed to the end user to handle a given request and the associated mock and response.
An object implementing this interface is passed to the hook function, under property
mock
of the single argument object.