-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-express.js
71 lines (57 loc) · 1.66 KB
/
test-express.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
63
64
65
66
67
68
69
70
71
var express = require('express')
, bodyParser = require('body-parser')
, tape = require('tape')
, common = require('./common.js')
, agnostic = require('../')
, bodyParserOptions = { limit: 100 }
;
tape.test('express as route, no parser', function(t)
{
var server
, app = express()
;
// plug-in request handlers
Object.keys(common.requests).forEach(function(id)
{
app.all([common.server.endpoint, id].join('/'), agnostic(common.requests[id].requestHandler));
});
// start the server
server = app.listen(common.server.port, function()
{
common.sendAllRequests.call(t, 'express', function(error, responded)
{
t.error(error);
t.equal(Object.keys(responded).length, Object.keys(common.requests).length, 'expect same number of responses as requests');
server.close(function()
{
t.end();
});
});
});
});
tape.test('express as route, with bodyParser middleware', function(t)
{
var server
, app = express()
;
// made it parse input from start
app.use(bodyParser.json(bodyParserOptions));
// plug-in request handlers
Object.keys(common.requests).forEach(function(id)
{
app.all([common.server.endpoint, id].join('/'), agnostic(common.requests[id].requestHandler));
});
// start the server
server = app.listen(common.server.port, function()
{
common.sendAllRequests.call(t, 'express', function(error, responded)
{
t.error(error);
t.equal(Object.keys(responded).length, Object.keys(common.requests).length, 'expect same number of responses as requests');
server.close(function()
{
t.end();
});
});
});
});