mono-test-utils
Utils for testing your Mono project.
Installation
npm install --save-dev mono-test-utils
Utils
const start stop url stdMock stdRestore $get $post $put $del} =
Contents
dir
directory with NODE_ENV=test
:
Start a Mono project from const context = await // context = { log, conf, app, server, stdout, stderr }
Default options
:
env: 'test' monoPath: 'mono-core'
Stop Mono server:
await
Get the url of your mono server:
// http://localhost:8000 (port updates depending of the mono conf)// http://localhost:8000/test
stdout
and stderr
Mock This is useful for capturing logs (based on std-mocks).
Example:
// Start mocking stdout and stderr consoleconsole const stdout stderr = // stdout = ['test log\n']// stderr = ['test error\n']
stdMock()
will callstdMocks.use(options)
stdRestore()
will callstdMocks.restore()
and returnstdMocks.flush()
.
Make HTTP requests to the API:
await await await await // alias: `$delete`
Also available: $head
, $options
and $patch
INFO: The options
are the same as request.
Every of the following methods return an object with these properties:
statusCode // HTTP status code headers // Headers sent back body // Body of the response stdout // Logs written on stdout during the request stderr // Logs written on stderr during the request
Example
Example of test/index.js
with ava:
const test = const join = const start stop $get $post = let context // Start servertest // Test API Endpoints // Close servertest