@metrics/test-consumer
This module is a memory based consumer for metrics streams to be used in tests. The purpose of the module is to make writing tests and asserting metrics easier. It takes a metric stream generated by @metrics/client and makes the collected metrics available as an array.
⚠️ You should never use this in produciton code, however it is very convenient when writing tests which produce metrics using @metrics/client
Examples usage
Below is a sample test showing how this could be used:
API
constructor(metrics)
Takes in the @metrics/client to collect metrics from.
.start()
Creates a readable stream which listens for metrics produced by the client.
.stop()
Ends the stream setup for the client, returns a Promise which resolves to an array with the metrics consumed.
async .getResults()
Returns a promise which resolves to an array containing collected [@metrics/metrics](https://metrics-js.github.io/reference/metric/)
objects.
createMetrics
Utility object with functions for creating mock Metric
objects, has the functions .timer
and .counter
.