Skip to content

Commit bf44d2b

Browse files
authored
[#391] Add tests to capture defect. (#393)
1 parent bf63dbf commit bf44d2b

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

test/support/proxyTarget.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ function proxyTarget(port, timeout, handlers) {
2828
});
2929
}
3030

31+
target.get('/get', function (req, res) {
32+
res.send('OK');
33+
});
34+
3135
target.post('/post', function(req, res) {
3236
req.pipe(res);
3337
});

test/traceDebugging.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
3+
var debug = require('debug');
4+
var express = require('express');
5+
var request = require('supertest');
6+
var proxy = require('../');
7+
var proxyTarget = require('../test/support/proxyTarget');
8+
9+
/* This test is specifically written because of critical errors thrown while debug logging. */
10+
describe.only('trace debugging does not cause the application to fail', function () {
11+
var proxyServer;
12+
13+
beforeEach(function () { debug.enable('express-http-proxy'); proxyServer = proxyTarget(3000); });
14+
afterEach(function () { debug.disable('express-http-proxy'); proxyServer.close(); });
15+
16+
it('happy path', function (done) {
17+
var app = express();
18+
app.use(proxy('localhost:3000'));
19+
request(app)
20+
.get('/get')
21+
.expect(200)
22+
.end(done);
23+
});
24+
25+
it('when agent is a deeply nested object', function (done) {
26+
var app = express();
27+
var HttpAgent = require('http').Agent;
28+
var httpAgent = new HttpAgent({ keepAlive: true, keepAliveMsecs: 60e3 });
29+
app.use(proxy('localhost:3000', {
30+
proxyReqOptDecorator: function (proxyReqOpts) {
31+
proxyReqOpts.agent = httpAgent;
32+
return proxyReqOpts;
33+
}
34+
}));
35+
request(app)
36+
.get('/get')
37+
.expect(200)
38+
.end(done);
39+
});
40+
});
41+

0 commit comments

Comments
 (0)