-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathchannels.js
More file actions
101 lines (63 loc) · 2.66 KB
/
Copy pathchannels.js
File metadata and controls
101 lines (63 loc) · 2.66 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
'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('hapi.onServer', () => {
const channel = DC.channel('hapi.onServer');
it('server should be exposed on creation through the channel hapi.onServer', async () => {
let server;
const exposedServer = await new Promise((resolve) => {
channel.subscribe(resolve);
server = Hapi.server();
});
expect(exposedServer).to.shallow.equal(server);
});
});
describe('hapi.onRoute', () => {
const channel = DC.channel('hapi.onRoute');
it('route should be exposed on creation through the channel hapi.onRoute', async () => {
const server = Hapi.server();
const exposedRoute = await new Promise((resolve) => {
channel.subscribe(resolve);
server.route({
method: 'GET',
path: '/',
options: { app: { x: 'o' } },
handler: () => 'ok'
});
});
expect(exposedRoute).to.be.an.object();
expect(exposedRoute.settings.app.x).to.equal('o');
});
});
describe('hapi.onResponse', () => {
const channel = DC.channel('hapi.onResponse');
it('response should be exposed on creation through the channel hapi.onResponse', async () => {
const server = Hapi.server();
server.route({ method: 'GET', path: '/', handler: () => 'ok' });
const event = new Promise((resolve) => {
channel.subscribe(resolve);
});
const response = await server.inject('/');
const responseExposed = await event;
expect(response.request.response).to.shallow.equal(responseExposed);
});
});
describe('hapi.onRequest', () => {
const channel = DC.channel('hapi.onRequest');
it('request should be exposed on creation through the channel hapi.onRequest', async () => {
const server = Hapi.server();
server.route({ method: 'GET', path: '/', handler: () => 'ok' });
const event = new Promise((resolve) => {
channel.subscribe(resolve);
});
const response = await server.inject('/');
const requestExposed = await event;
expect(response.request).to.shallow.equal(requestExposed);
});
});
});