-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
41 lines (33 loc) · 1009 Bytes
/
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
'use strict'
const { test } = require('tap')
const Fastify = require('fastify')
const { Sampler, errors } = require('@dnlup/doc')
const plugin = require('.')
test('invalid options', t => {
const fastify = Fastify()
return t.rejects(fastify.register(plugin, {
sampleInterval: -1
}), new errors.InvalidArgumentError('sampleInterval must be > 1, received -1'))
})
test('valid options', t => {
const fastify = Fastify()
return t.resolves(fastify.register(plugin))
})
test('metrics decorator', async t => {
const fastify = Fastify()
fastify.register(plugin, {
sampleInterval: 100,
unref: false
})
await fastify.ready()
t.ok(fastify.metrics instanceof Sampler)
await new Promise((resolve) => {
fastify.metrics.once('sample', () => {
resolve()
})
})
t.ok(typeof fastify.eventLoopUtilizationSupported === 'boolean')
t.ok(typeof fastify.resourceUsageSupported === 'boolean')
t.ok(typeof fastify.gcFlagsSupported === 'boolean')
await fastify.close()
})