Skip to content

Commit 2f265a2

Browse files
committed
[test] Updated node-http-proxy tests
1 parent e9511ea commit 2f265a2

File tree

1 file changed

+39
-35
lines changed

1 file changed

+39
-35
lines changed

Diff for: test/node-http-proxy-test.js

+39-35
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var vows = require('vows'),
3131

3232
require.paths.unshift(require('path').join(__dirname, '../lib/'));
3333

34-
var HttpProxy = require('node-http-proxy').HttpProxy;
34+
var httpProxy = require('node-http-proxy');
3535
var testServers = {};
3636

3737
//
@@ -77,7 +77,7 @@ var startTargetServer = function (port) {
7777
//
7878
var startTest = function (proxy, port) {
7979
testServers.noLatency = [];
80-
testServers.noLatency.push(startProxyServer('127.0.0.1', port, proxy));
80+
testServers.noLatency.push(startProxyServer('localhost', port, proxy));
8181
testServers.noLatency.push(startTargetServer(port));
8282
};
8383

@@ -86,44 +86,48 @@ var startTest = function (proxy, port) {
8686
//
8787
var startTestWithLatency = function (proxy, port) {
8888
testServers.latency = [];
89-
testServers.latency.push(startLatentProxyServer('127.0.0.1', port, proxy, 2000));
89+
testServers.latency.push(startLatentProxyServer('localhost', port, proxy, 2000));
9090
testServers.latency.push(startTargetServer(port));
9191
};
9292

93-
vows.describe('node-proxy').addBatch({
94-
"When an incoming request is proxied to the helloNode server" : {
95-
"with no latency" : {
96-
topic: function () {
97-
var proxy = new (HttpProxy);
98-
startTest(proxy, 8082);
99-
proxy.emitter.addListener('end', this.callback);
93+
vows.describe('node-http-proxy').addBatch({
94+
"A node-http-proxy": {
95+
"when instantiated directly": {
96+
"and an incoming request is proxied to the helloNode server" : {
97+
"with no latency" : {
98+
topic: function () {
99+
var proxy = new (httpProxy.HttpProxy);
100+
startTest(proxy, 8082);
101+
proxy.emitter.addListener('end', this.callback);
100102

101-
var client = http.createClient(8080, '127.0.0.1');
102-
var request = client.request('GET', '/');
103-
request.end();
104-
},
105-
"it should received 'hello world'": function (err, body) {
106-
assert.equal(body, 'hello world');
107-
testServers.noLatency.forEach(function (server) {
108-
server.close();
109-
})
110-
}
111-
},
112-
"with latency": {
113-
topic: function () {
114-
var proxy = new (HttpProxy);
115-
startTestWithLatency(proxy, 8083);
116-
proxy.emitter.addListener('end', this.callback);
103+
var client = http.createClient(8080, 'localhost');
104+
var request = client.request('GET', '/');
105+
request.end();
106+
},
107+
"it should received 'hello world'": function (err, body) {
108+
assert.equal(body, 'hello world');
109+
testServers.noLatency.forEach(function (server) {
110+
server.close();
111+
})
112+
}
113+
},
114+
"with latency": {
115+
topic: function () {
116+
var proxy = new (httpProxy.HttpProxy);
117+
startTestWithLatency(proxy, 8083);
118+
proxy.emitter.addListener('end', this.callback);
117119

118-
var client = http.createClient(8081, '127.0.0.1');
119-
var request = client.request('GET', '/');
120-
request.end();
121-
},
122-
"it should receive 'hello world'": function (err, body) {
123-
assert.equal(body, 'hello world');
124-
testServers.latency.forEach(function (server) {
125-
server.close();
126-
})
120+
var client = http.createClient(8081, 'localhost');
121+
var request = client.request('GET', '/');
122+
request.end();
123+
},
124+
"it should receive 'hello world'": function (err, body) {
125+
assert.equal(body, 'hello world');
126+
testServers.latency.forEach(function (server) {
127+
server.close();
128+
})
129+
}
130+
}
127131
}
128132
}
129133
}

0 commit comments

Comments
 (0)