-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.test.js
43 lines (35 loc) · 910 Bytes
/
server.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
import app from './server';
import http from 'http';
const makeRequest = (path, expectedContentType, expectedStatusCode, done) => {
const options = {
hostname: 'localhost',
port: 3000,
path: path,
method: 'GET'
};
const req = http.request(options, res => {
let data = '';
res.on('data', chunk => {
data += chunk;
});
res.on('end', () => {
try {
expect(res.headers['content-type']).toMatch(expectedContentType);
expect(res.statusCode).toBe(expectedStatusCode);
done();
} catch (error) {
done(error);
}
});
});
req.on('error', error => {
done(error);
});
req.end();
};
test('server is listening to / as an html', done => {
makeRequest('/', /html/, 200, done);
});
test('bundle.js is built and the server returns bundle.js', done => {
makeRequest('/bundle.js', /javascript/, 200, done);
});