-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathchannels.js
More file actions
121 lines (79 loc) · 3.05 KB
/
Copy pathchannels.js
File metadata and controls
121 lines (79 loc) · 3.05 KB
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
'use strict';
const DC = require('diagnostics_channel');
const Code = require('@hapi/code');
const Lab = require('@hapi/lab');
const Hapi = require('..');
const { describe, it } = exports.lab = Lab.script();
const expect = Code.expect;
describe('DiagnosticChannel', () => {
describe('onServerChannel', () => {
const channel = DC.channel('hapi.onServer');
it('server should be exposed on creation through the channel hapi.onServer', async () => {
let exposedServer;
let server;
await new Promise((resolve) => {
channel.subscribe((srv) => {
exposedServer = srv;
resolve();
});
server = Hapi.server();
});
expect(exposedServer).to.equal(server);
});
});
describe('onRouteChannel', () => {
const channel = DC.channel('hapi.onRoute');
it('route should be exposed on creation through the channel hapi.onRoute', async () => {
const server = Hapi.server();
let route;
await new Promise((resolve) => {
channel.subscribe((rte) => {
route = rte;
resolve();
});
server.route({
method: 'GET',
path: '/',
options: { app: { x: 'o' } },
handler: () => 'ok'
});
});
expect(route).to.be.an.object();
expect(route.settings.app.x).to.equal('o');
});
});
describe('onResponseChannel', () => {
const channel = DC.channel('hapi.onResponse');
it('response should be exposed on creation through the channel hapi.onResponse', async () => {
const server = Hapi.server();
let responseExposed;
server.route({ method: 'GET', path: '/', handler: () => 'ok' });
const eventPromise = new Promise((resolve) => {
channel.subscribe((res) => {
responseExposed = res;
resolve();
});
});
const response = await server.inject('/');
await eventPromise;
expect(response.request.response).to.equal(responseExposed);
});
});
describe('onRequestChannel', () => {
const channel = DC.channel('hapi.onRequest');
it('request should be exposed on creation through the channel hapi.onRequest', async () => {
const server = Hapi.server();
let requestExposed;
server.route({ method: 'GET', path: '/', handler: () => 'ok' });
const eventPromise = new Promise((resolve) => {
channel.subscribe((req) => {
requestExposed = req;
resolve();
});
});
const response = await server.inject('/');
await eventPromise;
expect(response.request).to.equal(requestExposed);
});
});
});