-
Notifications
You must be signed in to change notification settings - Fork 161
/
index.js
executable file
·146 lines (107 loc) · 3.42 KB
/
index.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
'use strict';
const Code = require('@hapi/code');
const Good = require('..');
const Hapi = require('@hapi/hapi');
const Lab = require('@hapi/lab');
const Oppsy = require('@hapi/oppsy');
const Reporters = require('./fixtures/reporters');
const Monitor = require('../lib/monitor');
const internals = {};
const { describe, it } = exports.lab = Lab.script();
const { expect } = Code;
internals.reporters = {
foo: [
new Reporters.Incrementer(10, 5),
new Reporters.Stringify(),
new Reporters.Writer()
]
};
describe('good', () => {
it('starts the Monitor object during registration', { plan: 1 }, async () => {
const plugin = {
plugin: Good,
options: {
reporters: internals.reporters
}
};
const server = new Hapi.Server();
let called = false;
const start = Monitor.prototype.start;
Monitor.prototype.start = function () {
called = true;
return start.call(this);
};
await server.register(plugin);
expect(called).to.be.true();
});
it('starts the ops monitor when the server starts', { plan: 1 }, async () => {
const plugin = {
plugin: Good,
options: {
reporters: internals.reporters,
ops: {
interval: 2000
}
}
};
const server = new Hapi.Server();
const start = Oppsy.prototype.start;
await server.register(plugin);
Oppsy.prototype.start = (interval) => {
Oppsy.prototype.start = start;
expect(interval).to.equal(2000);
};
await server.start();
});
it('stops the monitor when the server stops', { plan: 1 }, async () => {
const plugin = {
plugin: Good,
options: {
reporters: internals.reporters
}
};
const server = new Hapi.Server();
let called = false;
const stop = Monitor.prototype.stop;
Monitor.prototype.stop = function () {
called = true;
return stop.call(this);
};
await server.register(plugin);
await server.stop();
expect(called).to.be.true();
});
it('supports a mix of reporter options', async () => {
const plugin = {
plugin: Good,
options: {
reporters: {
foo: [
new Reporters.Incrementer(2),
new Reporters.Incrementer(4), {
module: '../test/fixtures/reporters',
name: 'Writer',
args: [{ objectMode: true }]
}
]
}
}
};
const server = new Hapi.Server();
await server.register(plugin);
});
it('allows starting with no reporters', async () => {
const server = new Hapi.Server();
await server.register(Good);
});
it('throws an error if invalid extension events are used', { plan: 1 }, async () => {
const plugin = {
plugin: Good,
options: {
extensions: ['response']
}
};
const server = new Hapi.Server();
await expect(server.register(plugin)).to.reject(/contains an invalid value/);
});
});