Version: 2.3.0

Configuration file

Options#

Low level configuration and options can be defined modifying the mocks.config.js file in the root folder of your project (a custom file path can be defined using the configFile low level configuration property).

The first level properties returned by this configuration file will be interpreted as low level configuration properties.

Properties returned inside the options object will be considered as main options or plugins extra options.

Formats#

Object#

The configuration file can export an object containing configuration and options:

// mocks.config.js
const FooPlugin = require("mocks-server-plugin-foo");
const FooRoutesHandler = require("mocks-server-routes-handler-foo");
module.exports = {
babelRegister: true,
addPlugins: [FooPlugin],
addRoutesHandlers: [FooRoutesHandler],
options: {
path: "custom-mocks-folder",
port: 3200,
mock: "foo-mock",
cli: false,
cors: true,
corsPreFlight: false,
}
};

Function#

The configuration file can export a function. The function receives previously defined configuration (from previous config methods) that can be modified.

// mocks.config.js
const FooPlugin = require("mocks-server-plugin-foo");
module.exports = (config) => {
config.plugins.push(FooPlugin);
config.options.behavior = "foo-behavior";
return config;
};

Async#

The configuration file can also export an async function, or a function returning a Promise:

// mocks.config.js
const getMockAsyncMethod = require("./getMockAsync");
module.exports = async (config) => {
config.options.mock = await getMockAsyncMethod();
return config;
};
// mocks.config.js
const getAsyncConfig = require("./getAsyncConfig");
module.exports = () => {
return getAsyncConfig()
.then(config => {
console.log(config);
return config;
});
};