-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
73 lines (49 loc) · 1.5 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
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
'use strict';
const test = require('ava');
const Hapi = require('@hapi/hapi');
const Wreck = require('@hapi/wreck');
const routes = require('./routes');
test('route / should return ok on GET inject', async (t) => {
const server = Hapi.server();
server.route(routes);
const { statusCode, payload } = await server.inject('/');
t.is(payload, 'ok');
t.is(statusCode, 200);
});
test('route / should return ok on GET request', async (t) => {
const server = Hapi.server();
server.route(routes);
await server.start();
const { res, payload } = await Wreck.get(`${server.info.uri}/`);
t.is(payload.toString(), 'ok');
t.is(res.statusCode, 200);
});
test('initialize server to have cache configured', async (t) => {
const server = Hapi.server();
server.ext({
type: 'onPreStart',
async method(s) {
server.app.value = 1;
}
});
await server.initialize();
t.is(server.app.value, 1);
});
test.cb('listen to custom event',(t) => {
const server = Hapi.server();
server.event('custom');
server.events.on('custom', (message) => {
t.is(message, 'ok');
t.end();
});
server.events.emit('custom', 'ok');
});
test('listen to custom event await', async (t) => {
t.plan(1); // change to 0 to see it fail
const server = Hapi.server();
server.event('custom');
server.events.on('custom', (message) => {
t.is(message, 'ok');
});
await server.events.emit('custom', 'ok');
});