1.0.3 • Published 7 years ago
@bb-cli/bb-convert-plugin-delay-response v1.0.3
BB-Convert Delay Response plugin middleware
This plugin will make any HTTP service response to be delayed a random amount of time before it gets resolved with the original result. Useful to check loading states, mimicking response latencies over the network.
Install alongside bb-convert (prefer global)
npm i -g @bb-cli/bb-convert-plugin-delay-response
Usage
bb-convert raml --transform-plugins @bb-cli/bb-convert-plugin-delay-response --template mock-ng
# OR
bb-convert raml --transform-plugins delay-response --template mock-ng
Configure in .bbconfig
Delay Response plugin can be configured in .bbconfig file:
{
"default": {
"convert": {
"raml": {
"transform-plugins": "delay-response"
}
}
}
}
With this configuration in place, you can simply run
bb-convert raml --template mock-ng
Create custom plugin
Plugin can customize minimum and maximum delay time parameters to be applied to every response. Delay can be fixed if only minimum delay is provided to the plugin factory.
// Custom plugin code example
const delayResponse = require('@bb-cli/bb-convert-plugin-delay-response');
const minDelay = 1000;
const maxDelay = 5000;
// Creates a function that returns a promise fulfilled after a random time
// between 1s and 5s
module.exports = delayResponse.pluginFnFactory(minDelay, maxDelay);