forked from doug-wade/react-server-styled-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
39 lines (33 loc) · 808 Bytes
/
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
import cp from 'child_process';
import http from 'http';
import test from 'ava';
let rs;
test.before('start the server', async () => {
rs = cp.spawn('npm', ['start']);
rs.stderr.on('data', data => console.error(`ERR: ${data}`));
await sleep(10000);
});
test('server is running', async t => {
t.is(200, await getResponseCode('/'));
});
test.after.always('shut down the server', async () => {
rs.kill('SIGHUP');
});
// gets the response code for an http request
function getResponseCode(url) {
return new Promise((resolve, reject) => {
const req = http.get({
hostname: 'localhost',
port: 3000,
path: url,
}, res => {
resolve(res.statusCode);
});
req.on('error', e => reject(e));
});
}
function sleep(time) {
return new Promise(resolve => {
setTimeout(resolve, time);
});
}