-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-http-unsupported.js
54 lines (45 loc) · 1.3 KB
/
test-http-unsupported.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
var http = require('http')
, events = require('events')
, tape = require('tape')
, hyperquest = require('hyperquest')
, common = require('./common.js')
, agnostic = require('../')
;
tape.test('unsupported http server', function(t)
{
var server, endpoint = agnostic(t.fail.bind(t, 'should not come to this'));
server = http.createServer(function(req, res)
{
var request = new events.EventEmitter();
request.headers = req.headers;
request.method = req.method;
request.url = req.url;
// emulate some hapi-like weird web server
t.throws(function()
{
endpoint(request, res);
}, /Unsupported http server type/, 'expect to throw upon invoked request handler');
// emulate just weird web server
t.throws(function()
{
endpoint({
headers: req.headers,
method : req.method,
url : req.url
}, res);
}, /Unsupported http server type/, 'expect to throw upon invoked request handler');
res.end();
});
// no need to start the server
server.listen(common.server.port, function()
{
hyperquest('http://localhost:' + common.server.port + common.server.endpoint, function(error)
{
t.error(error);
server.close(function()
{
t.end();
});
});
});
});