Skip to content

Commit fb19107

Browse files
committed
feat: uses default export and updated types
BREAKING CHANGE: Changed to using a default export for TestConsumer and added a named export for 'createMetric' utility object. Updated types to contain all exports.
1 parent f6cf17b commit fb19107

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Below is a sample test showing how this could be used:
1818
```js
1919
const test = require('tap');
2020
const Metrics = require('@metrics/client');
21-
const { TestConsumer } = require('@metrics/test-consumer');
21+
const TestConsumer = require('@metrics/test-consumer');
2222

2323
test('some test case', async () => {
2424
const metrics = new Metrics();
@@ -48,6 +48,7 @@ test('some test case', async () => {
4848
- [start](#start)
4949
- [stop](#stop)
5050
- [getResults](#async-getresults)
51+
- [createMetrics](#createmetrics)
5152

5253
### constructor(metrics)
5354

@@ -63,4 +64,8 @@ Ends the stream setup for the client, returns a Promise which resolves to an arr
6364

6465
### async .getResults()
6566

66-
Returns a promise which resolves to an array containing collected `[@metrics/metrics](https://metrics-js.github.io/reference/metric/)` objects.
67+
Returns a promise which resolves to an array containing collected `[@metrics/metrics](https://metrics-js.github.io/reference/metric/)` objects.
68+
69+
### createMetrics
70+
71+
Utility object with functions for creating mock `Metric` objects, has the functions `.timer` and `.counter`.

lib/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,5 @@ const createMetric = {
149149
}),
150150
};
151151

152-
module.exports = {
153-
TestConsumer,
154-
createMetric,
155-
};
152+
module.exports = TestConsumer;
153+
module.exports.createMetric = createMetric;

test-consumer.d.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
1-
import MetricsClient, {MetricsCounter, MetricsGauge, MetricsHistogram, MetricsSummary} from '@metrics/client';
1+
import MetricsClient from '@metrics/client';
22
import Metric from "@metrics/metric";
33

4-
declare class TestConsumer {
4+
declare class TestConsumer {
55
constructor(metrics: MetricsClient);
6+
67
start();
8+
79
stop();
10+
811
getResults(): Promise<Array<Metric>>;
912
}
13+
14+
declare namespace TestConsumer {
15+
/**
16+
* Contains utility functions for creating `Metrics` objects in tests.
17+
*/
18+
export interface CreateMetric {
19+
timer: (options: CreateMetricOptions) => Metric;
20+
counter: (options: CreateMetricOptions) => Metric;
21+
}
22+
23+
type CreateMetricOptions = {
24+
uri?: string;
25+
method?: string;
26+
status?: number | string;
27+
type?: string | Object
28+
}
29+
export const createMetric: CreateMetric;
30+
}
1031
export = TestConsumer;

test/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
const { test } = require("tap");
44
const MetricsClient = require("@metrics/client");
55

6-
const { TestConsumer, createMetric } = require("../lib/index");
6+
const TestConsumer = require("../lib/index");
7+
const { createMetric } = TestConsumer;
78

89
test("has a start and stop method", async (t) => {
910
const testHelper = new TestConsumer(new MetricsClient());

0 commit comments

Comments
 (0)