44[ ![ GitHub Actions status] ( https://github.com/metrics-js/prometheus-consumer/workflows/Run%20Lint%20and%20Tests/badge.svg )] ( https://github.com/metrics-js/test-consumer/actions?query=workflow%3A%22Run+Lint+and+Tests%22 )
55[ ![ Known Vulnerabilities] ( https://snyk.io/test/github/metrics-js/prometheus-consumer/badge.svg?targetFile=package.json )] ( https://snyk.io/test/github/metrics-js/test-consumer?targetFile=package.json )
66
7-
8-
97This 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.
108It takes a metric stream generated by @metrics/client and makes the collected metrics available as an array.
119
@@ -22,32 +20,31 @@ const MetricsClient = require("@metrics/client");
2220const TestConsumer = require (" @metrics/test-consumer" );
2321
2422test (" some test case" , async () => {
25- // Pass in the metrics client you want to consume.
26- const metrics = new MetricsClient ();
27- const testHelper = new TestConsumer (metrics);
28- // Sets up the consumer to capture events.
29- testHelper .start ();
23+ // Pass in the metrics client you want to consume.
24+ const metrics = new MetricsClient ();
25+ const testHelper = new TestConsumer (metrics);
26+ // Sets up the consumer to capture events.
27+ testHelper .start ();
3028
31- // 👋 Your code which produces some kind of metric goes here.
29+ // 👋 Your code which produces some kind of metric goes here.
3230
33- // Ends the streams, now we can get the result.
34- testHelper .stop ();
31+ // Ends the streams, now we can get the result.
32+ testHelper .stop ();
3533
36- const result = await testHelper .getResults ();
37- const metric = result .find ((m ) => m .name === " some_counter" );
34+ const result = await testHelper .getResults ();
35+ const metric = result .find ((m ) => m .name === " some_counter" );
3836
39- assert .ok (metric, " Expected to find metric some_counter" );
40- assert .equal (metric .value , 2 );
37+ assert .ok (metric, " Expected to find metric some_counter" );
38+ assert .equal (metric .value , 2 );
4139});
4240```
4341
4442## API
4543
46- - [ constructor] ( #constructormetrics )
47- - [ start] ( #start )
48- - [ stop] ( #stop )
49- - [ getResults] ( #async-getresults )
50- - [ createMetrics] ( #createmetrics )
44+ - [ constructor] ( #constructormetrics )
45+ - [ start] ( #start )
46+ - [ stop] ( #stop )
47+ - [ getResults] ( #async-getresults )
5148
5249### constructor(metrics)
5350
@@ -64,7 +61,3 @@ Ends the stream setup for the client, returns a Promise which resolves to an arr
6461### async .getResults()
6562
6663Returns a promise which resolves to an array containing collected ` [@metrics/metrics](https://metrics-js.github.io/reference/metric/) ` objects.
67-
68- ### createMetrics
69-
70- Utility object with functions for creating mock ` Metric ` objects, has the functions ` .timer ` and ` .counter ` .
0 commit comments