-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
62 lines (54 loc) · 1.4 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
var test = require('tape');
var serveit2 = require('./index');
var fs = require('fs');
var spdy = require('spdy');
var http = require('https');
// check if the server surfs correct status codes
test('statusCode test', function(t) {
t.plan(1);
var agent = spdy.createAgent({
host: 'localhost',
port: 7000,
agent: false,
rejectUnauthorized: false,
});
var server = serveit2({port: 7000, quiet: true}, function() {
http.get({
host: 'localhost',
path: '/README.md',
agent: agent,
}, function(res) {
t.equal(res.statusCode, 200);
agent.close();
server.close();
}).end();
});
});
// check if the server delivers correct contents
test('contents test', function(t) {
t.plan(1);
var agent = spdy.createAgent({
host: 'localhost',
port: 7000,
agent: false,
rejectUnauthorized: false,
});
var server = serveit2({port: 7000, quiet: true}, function() {
var contentsFromFile = fs.readFileSync(__dirname + '/README.md', 'utf8');
http.get({
host: 'localhost',
agent: agent,
path: '/README.md',
}, function(res) {
var contentsFromServer = '';
res.on('data', function(data) {
contentsFromServer += data.toString();
});
res.on('end', function() {
t.equal(contentsFromServer, contentsFromFile);
agent.close();
server.close();
});
}).end();
});
});