A simple node package that lets you manage your Mountebank test server. Based on https://www.npmjs.com/package/@toincrease/node-mountebank, but
Install Mountebank locally or run in docker. The easiest local install is as follows, otherwise check out options in the integration-tests.
npm install -g mountebank --production
Start Mountebank:
mb
I recommend reading the Mountebank documentation for a deeper understanding of their API.
For more samples on how to use this package check this blog: https://angela-evans.com/easy-api-tests-with-mountebank/ or the integration tests.
const mb = new Mountebank();
let imposter = new Imposter().withPort(port).withStub(
new DefaultStub(testPath, HttpMethod.GET, 'testbody', 222));
await mb.createImposter(imposter);
Add a query to the stub. For usages check the tests in ./integration-tests/predicate.flexi-predicate.query.mb-tests.ts
new Stub()
.withPredicate(
new FlexiPredicate()
.withOperator(Operator.equals)
.withPath('/testpath')
.withQuery({name: 'x', max: 5})
)
.withResponse(new DefaultResponse('found', 222))
A simple proxy which always proxies the request and records the responses. This is useful to
// forward all requestsfrom port 5000 => 5001 and generate response stubs
let proxyImposter = new Imposter()
.withPort(5000)
.withStub(new Stub()
.withProxy(new DebugProxy(`http://localhost:5001}`)));
await mb.createImposter(proxyImposter);
You can use devbox.sh from jetpack.io to setup the local dev environment tooling.
devbox shell
Check the integration-tests for notes on how to run and test the package locally.