-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest.js
81 lines (61 loc) · 1.34 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
74
75
76
77
78
79
80
81
import test from 'ava';
import delay from 'delay';
import createTestServer from 'create-test-server';
import waitForLocalhost from './index.js';
test('main', async t => {
t.plan(2);
const server = await createTestServer();
server.head('/', async (request, response) => {
await delay(1000);
response.end();
t.pass();
});
await waitForLocalhost({port: server.port});
t.pass();
await server.close();
});
test('use get method', async t => {
t.plan(2);
const server = await createTestServer();
server.get('/', async (request, response) => {
await delay(1000);
response.end();
t.pass();
});
await waitForLocalhost({
port: server.port,
useGet: true,
});
t.pass();
await server.close();
});
test('use custom path', async t => {
t.plan(2);
const server = await createTestServer();
server.get('/health', async (request, response) => {
await delay(1000);
response.end();
t.pass();
});
await waitForLocalhost({
port: server.port,
path: '/health',
});
t.pass();
await server.close();
});
test('use custom statusCodes', async t => {
t.plan(2);
const server = await createTestServer();
server.get('/', async (request, response) => {
await delay(1000);
response.status(202).end();
t.pass();
});
await waitForLocalhost({
port: server.port,
statusCodes: [201, 202],
});
t.pass();
await server.close();
});