Skip to content

Commit 1429c91

Browse files
improve tests
1 parent d1a28f9 commit 1429c91

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

test/01_proxy.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ var testUrlA = 'http://' + testHost + ':' + testPortA;
1818
var testUrlB = 'http://' + testHost + ':' + testPortB;
1919

2020
var getHttp = function (url, cb) {
21-
request({ url: url }, function (err, body, resp) {
22-
cb(err, body, resp);
21+
request({ url: url }, function (err, resp, body) {
22+
cb(err, resp, body);
2323
});
2424
};
2525

2626
var proxyHttp = function (url, cb) {
27-
request({ url: url, proxy: 'http://127.0.0.1:' + testProxyPort, ca: fs.readFileSync(__dirname + '/../.http-mitm-proxy/certs/ca.pem') }, function (err, body, resp) {
28-
cb(err, body, resp);
27+
request({ url: url, proxy: 'http://127.0.0.1:' + testProxyPort, ca: fs.readFileSync(__dirname + '/../.http-mitm-proxy/certs/ca.pem') }, function (err, resp, body) {
28+
cb(err, resp, body);
2929
});
3030
};
3131

@@ -72,14 +72,11 @@ describe('proxy', function () {
7272

7373
beforeEach(function (done) {
7474
proxy = new Proxy();
75-
proxy.listen({ port: testProxyPort, silent: true });
76-
setTimeout(function () {
77-
done();
78-
}, 15);
75+
proxy.listen({ port: testProxyPort }, done);
7976
});
8077

8178
afterEach(function () {
82-
proxy.httpServer.close();
79+
proxy.close();
8380
proxy = null;
8481
});
8582

@@ -133,6 +130,7 @@ describe('proxy', function () {
133130
describe('proxy a 1024 byte file', function () {
134131
it('a', function (done) {
135132
proxyHttp(testUrlA + '/1024', function (err, resp, body) {
133+
if (err) return done(new Error(err.message+" "+JSON.stringify(err)));
136134
var len = 0;
137135
if (body.hasOwnProperty('length')) len = body.length;
138136
assert.equal(1024, len);
@@ -142,7 +140,7 @@ describe('proxy', function () {
142140
});
143141
it('b', function (done) {
144142
proxyHttp(testUrlB + '/1024', function (err, resp, body) {
145-
if (err) console.log('proxyHttpB Error: ' + err.toString());
143+
if (err) return done(new Error(err.message+" "+JSON.stringify(err)));
146144
var len = 0;
147145
if (body.hasOwnProperty('length')) len = body.length;
148146
assert.equal(1024, len);
@@ -154,7 +152,7 @@ describe('proxy', function () {
154152
describe('ssl', function () {
155153
it('proxys to google.com using local ca file', function (done) {
156154
proxyHttp('https://www.google.com/', function (err, resp, body) {
157-
if (err) console.log('Error: ' + err.toString());
155+
if (err) return done(new Error(err.message+" "+JSON.stringify(err)));
158156
assert.equal(200, resp.statusCode, '200 Status code from Google.');
159157
done();
160158
});
@@ -185,6 +183,7 @@ describe('proxy', function () {
185183
});
186184

187185
proxyHttp(testUrlA + '/1024', function (err, resp, body) {
186+
if (err) return done(new Error(err.message+" "+JSON.stringify(err)));
188187
var len = 0;
189188
if (body.hasOwnProperty('length')) len = body.length;
190189
assert.equal(1024, len);

0 commit comments

Comments
 (0)