-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest.js
45 lines (36 loc) · 1.02 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
import http from 'http';
import {serial as test} from 'ava';
import getPort from 'get-port';
import m from '.';
const srv = () => http.createServer((req, res) => {
res.end();
});
test('success', async t => {
const port = await getPort();
const server = srv().listen(port);
t.truthy(await m(port));
server.close();
});
test('fail', async t => {
await t.throws(m(0), 'Couldn\'t find a process with port `0`');
await t.throws(m.all([0]), 'Couldn\'t find a process with port `0`');
});
test('accepts a number', async t => {
await t.throws(m('foo'), 'Expected a number, got string');
});
test('all', async t => {
const [p1, p2] = await Promise.all([getPort(), getPort()]);
const [s1, s2] = [srv().listen(p1), srv().listen(p2)];
const ports = await m.all([p1, p2]);
t.true(ports instanceof Map);
for (const x of ports.values()) {
t.is(typeof x, 'number');
}
s1.close();
s2.close();
});
test('list', async t => {
const list = await m.list();
t.true(list instanceof Map);
await t.notThrows(m.all(Array.from(list.keys())));
});