-
Notifications
You must be signed in to change notification settings - Fork 20
/
test.js
48 lines (33 loc) · 1.26 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* eslint-env jest */
'use strict';
const promRegister = require('prom-client').register;
const PromRegistry = require('prom-client').Registry;
const gcMetrics = require('./index');
jest.mock('@sematext/gc-stats');
afterEach(() => {
promRegister.clear();
});
test('register metrics', async () => {
expect(await promRegister.getMetricsAsJSON()).toHaveLength(0);
gcMetrics();
expect(await promRegister.getMetricsAsJSON()).toHaveLength(3);
});
test('register metrics to custom register', async () => {
const register = new PromRegistry();
expect(await promRegister.getMetricsAsJSON()).toHaveLength(0);
expect(await register.getMetricsAsJSON()).toHaveLength(0);
gcMetrics(register);
expect(await promRegister.getMetricsAsJSON()).toHaveLength(0);
expect(await register.getMetricsAsJSON()).toHaveLength(3);
});
test('include prefix', async () => {
expect(await promRegister.getMetricsAsJSON()).toHaveLength(0);
gcMetrics(undefined, { prefix: 'prefix_' });
const metricsAsJson = await promRegister.getMetricsAsJSON();
expect(metricsAsJson).toHaveLength(3);
expect(metricsAsJson.map(metric => metric.name)).toEqual([
'prefix_nodejs_gc_runs_total',
'prefix_nodejs_gc_pause_seconds_total',
'prefix_nodejs_gc_reclaimed_bytes_total',
]);
});