Webpack Dev Server mocking engine
npm i --save devmock
or
yarn add devmock
And require it for further usage
const { DevMock } = require("devmock")
devServer: {
before: DevMock.v3({
mocksPath: path.resolve("mocks/**/*.mock.js")
})
}
devServer: {
onBeforeSetupMiddleware: DevMock.make({
mocksPath: path.resolve("mocks/**/*.mock.js")
})
}
DevMock.make({
mocksPath: "mocks/*.mock.js", // glob supported path to your mock files (required)
})
DevMock.make
and DevMock.v3
has the same params.
// mocks/exmaple.mock.js
module.exports = {
path: "/users", // Query path (required)
method: "GET", // HTTP method (optional, default: GET)
delay: 300, // Response delay in ms (optional, default: 0)
status: 200, // Response status code (options, default: 200)
response: [ // Response object (optional, default: {})
{ id: 1, name: "John" },
{ id: 2, name: "Mary" },
{ id: 3, name: "Bob" },
]
}
Both status
and response
params can be a function of request params:
module.exports = {
path: "/users",
status: params => params.error ? 422 : 200,
response: params => params.error ? { success: false } : { success: true }
}
- Fork it ( https://github.com/Cado-Labs/devmock )
- Create your feature branch (
git checkout -b feature/my-new-feature
) - Commit your changes (
git commit -am '[feature_context] Add some feature'
) - Push to the branch (
git push origin feature/my-new-feature
) - Create new Pull Request
Released under MIT License.