Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing http tests to avoid hanging when assertions fail #4435

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
105 changes: 43 additions & 62 deletions test/unit/adapters/http.js
Expand Up @@ -21,12 +21,9 @@ describe('supports http with nodejs', function () {
proxy.close();
proxy = null;
}
if (process.env.http_proxy) {
delete process.env.http_proxy;
}
if (process.env.no_proxy) {
delete process.env.no_proxy;
}
delete process.env.http_proxy;
delete process.env.https_proxy;
delete process.env.no_proxy;
jasonsaayman marked this conversation as resolved.
Show resolved Hide resolved
});

it('should throw an error if the timeout property is not parsable as a number', function (done) {
Expand Down Expand Up @@ -160,7 +157,7 @@ describe('supports http with nodejs', function () {
axios.get('http://localhost:4444/').then(function (res) {
assert.deepEqual(res.data, data);
done();
});
}).catch(done);
jasonsaayman marked this conversation as resolved.
Show resolved Hide resolved
});
});

Expand All @@ -180,7 +177,7 @@ describe('supports http with nodejs', function () {
axios.get('http://localhost:4444/').then(function (res) {
assert.deepEqual(res.data, data);
done();
});
}).catch(done);;
});
});

Expand All @@ -202,7 +199,7 @@ describe('supports http with nodejs', function () {
assert.equal(res.data, str);
assert.equal(res.request.path, '/two');
done();
});
}).catch(done);;
});
});

Expand All @@ -221,7 +218,7 @@ describe('supports http with nodejs', function () {
assert.equal(res.status, 302);
assert.equal(res.headers['location'], '/foo');
done();
});
}).catch(done);;
});
});

Expand All @@ -235,9 +232,10 @@ describe('supports http with nodejs', function () {
}).listen(4444, function () {
axios.get('http://localhost:4444/', {
maxRedirects: 3
}).catch(function (error) {
}).catch(function(error) {
assert.equal(error.code, 'ERR_FR_TOO_MANY_REDIRECTS');
jasonsaayman marked this conversation as resolved.
Show resolved Hide resolved
done();
});
}).catch(done);
});
});

Expand All @@ -261,9 +259,7 @@ describe('supports http with nodejs', function () {
axios.head('http://localhost:4444/one').then(function (res) {
assert.equal(res.status, 200);
done();
}).catch(function (err) {
done(err);
});
}).catch(done);
jasonsaayman marked this conversation as resolved.
Show resolved Hide resolved
});
});

Expand All @@ -284,9 +280,8 @@ describe('supports http with nodejs', function () {
axios.get('http://localhost:4444/').then(function (res) {
assert.deepEqual(res.data, data);
done();
});
}).catch(done);
});

});
});

Expand All @@ -298,7 +293,7 @@ describe('supports http with nodejs', function () {
}).listen(4444, function () {
axios.get('http://localhost:4444/').catch(function (error) {
done();
});
}).catch(done);
});
});

Expand All @@ -318,7 +313,7 @@ describe('supports http with nodejs', function () {
}).then(function(res) {
assert.equal(res.data.toString('base64'), zipped.toString('base64'));
done();
});
}).catch(done);
});
});
});
Expand All @@ -333,7 +328,7 @@ describe('supports http with nodejs', function () {
axios.get('http://localhost:4444/').then(function (res) {
assert.equal(res.data, str);
done();
});
}).catch(done);
});
});

Expand All @@ -347,7 +342,7 @@ describe('supports http with nodejs', function () {
var base64 = Buffer.from(user + ':', 'utf8').toString('base64');
assert.equal(res.data, 'Basic ' + base64);
done();
});
}).catch(done);
});
});

Expand All @@ -361,7 +356,7 @@ describe('supports http with nodejs', function () {
var base64 = Buffer.from('foo:bar', 'utf8').toString('base64');
assert.equal(res.data, 'Basic ' + base64);
done();
});
}).catch(done);
});
});

Expand All @@ -372,7 +367,7 @@ describe('supports http with nodejs', function () {
axios.get('http://localhost:4444/').then(function (res) {
assert.ok(/^axios\/[\d.]+$/.test(res.data), `User-Agent header does not match: ${res.data}`);
done();
});
}).catch(done);
});
});

Expand All @@ -384,7 +379,7 @@ describe('supports http with nodejs', function () {
axios.get('http://localhost:4444/', { headers }).then(function (res) {
assert.equal(res.data, 'foo bar');
done();
});
}).catch(done);
});
});

Expand All @@ -396,7 +391,7 @@ describe('supports http with nodejs', function () {
var headers = { 'CoNtEnT-lEnGtH': '42' }; // wonky casing to ensure caseless comparison
axios.post('http://localhost:4444/', 'foo', { headers }).then(function () {
done();
});
}).catch(done);
});
});

Expand Down Expand Up @@ -494,7 +489,7 @@ describe('supports http with nodejs', function () {

it('should display error while parsing params', function (done) {
server = http.createServer(function () {

}).listen(4444, function () {
axios.get('http://localhost:4444/', {
params: {
Expand All @@ -503,7 +498,7 @@ describe('supports http with nodejs', function () {
}).catch(function (err) {
assert.deepEqual(err.exists, true)
done();
});
}).catch(done);
});
});

Expand All @@ -528,11 +523,7 @@ describe('supports http with nodejs', function () {
assert.equal(resp.status, 200);
assert.equal(resp.statusText, 'OK');
done();
})
.catch(function (error) {
assert.ifError(error);
done();
});
}).catch(done);
});
});

Expand All @@ -553,7 +544,7 @@ describe('supports http with nodejs', function () {
assert.equal(string, fs.readFileSync(__filename, 'utf8'));
done();
});
});
}).catch(done);
});
});

Expand All @@ -566,11 +557,11 @@ describe('supports http with nodejs', function () {
axios.post('http://localhost:4444/',
fs.createReadStream(notExitPath)
).then(function (res) {
assert.fail();
assert.fail('expected ENOENT error');
}).catch(function (err) {
assert.equal(err.message, `ENOENT: no such file or directory, open \'${notExitPath}\'`);
done();
});
}).catch(done);
});
});

Expand All @@ -593,7 +584,7 @@ describe('supports http with nodejs', function () {
assert.equal(string, buf.toString());
done();
});
});
}).catch(done);
});
});

Expand Down Expand Up @@ -630,7 +621,7 @@ describe('supports http with nodejs', function () {
}).then(function (res) {
assert.equal(res.data, '123456789', 'should pass through proxy');
done();
});
}).catch(done);
});
});
});
Expand Down Expand Up @@ -678,10 +669,7 @@ describe('supports http with nodejs', function () {
}).then(function (res) {
assert.equal(res.data, '123456789', 'should pass through proxy');
done();
}).catch(function (err) {
assert.fail(err);
done()
});
}).catch(done);
});
});
});
Expand All @@ -699,7 +687,7 @@ describe('supports http with nodejs', function () {
}).then(function (res) {
assert.equal(res.data, '123456789', 'should not pass through proxy');
done();
});
}).catch(done);
});
});

Expand Down Expand Up @@ -734,7 +722,7 @@ describe('supports http with nodejs', function () {
axios.get('http://localhost:4444/').then(function (res) {
assert.equal(res.data, '45671234', 'should use proxy set by process.env.http_proxy');
done();
});
}).catch(done);
});
});
});
Expand Down Expand Up @@ -779,12 +767,7 @@ describe('supports http with nodejs', function () {
}).then(function (res) {
assert.equal(res.data, '123456789', 'should pass through proxy');
done();
}).catch(function (err) {
assert.fail(err);
done()
}).finally(function () {
process.env.https_proxy = ''
});
}).catch(done);
});
});
});
Expand Down Expand Up @@ -821,7 +804,7 @@ describe('supports http with nodejs', function () {
axios.get('http://localhost:4444/').then(function (res) {
assert.equal(res.data, '4567', 'should not use proxy for domains in no_proxy');
done();
});
}).catch(done);
});
});
});
Expand Down Expand Up @@ -858,7 +841,7 @@ describe('supports http with nodejs', function () {
axios.get('http://localhost:4444/').then(function (res) {
assert.equal(res.data, '45671234', 'should use proxy for domains not in no_proxy');
done();
});
}).catch(done);
});
});
});
Expand Down Expand Up @@ -901,7 +884,7 @@ describe('supports http with nodejs', function () {
var base64 = Buffer.from('user:pass', 'utf8').toString('base64');
assert.equal(res.data, 'Basic ' + base64, 'should authenticate to the proxy');
done();
});
}).catch(done);
});
});
});
Expand Down Expand Up @@ -937,7 +920,7 @@ describe('supports http with nodejs', function () {
var base64 = Buffer.from('user:pass', 'utf8').toString('base64');
assert.equal(res.data, 'Basic ' + base64, 'should authenticate to the proxy set by process.env.http_proxy');
done();
});
}).catch(done);
});
});
});
Expand Down Expand Up @@ -983,7 +966,7 @@ describe('supports http with nodejs', function () {
var base64 = Buffer.from('user:pass', 'utf8').toString('base64');
assert.equal(res.data, 'Basic ' + base64, 'should authenticate to the proxy');
done();
});
}).catch(done);
});
});
});
Expand Down Expand Up @@ -1014,7 +997,7 @@ describe('supports http with nodejs', function () {
assert.equal(res.config.baseURL, 'http://localhost:4444/');
assert.equal(res.config.url, '/foo');
done();
});
}).catch(done);
});
});

Expand All @@ -1026,7 +1009,7 @@ describe('supports http with nodejs', function () {
axios.get('http://localhost:4444/'
).then(function (res) {
done();
});
}).catch(done);
});
});

Expand All @@ -1040,10 +1023,9 @@ describe('supports http with nodejs', function () {
headers: {
"User-Agent": null
}
}
).then(function (res) {
}).then(function (res) {
done();
});
}).catch(done);
});
});

Expand All @@ -1068,15 +1050,14 @@ describe('supports http with nodejs', function () {
}).catch(function (err) {
error = err;
failure = true;
}).finally(function () {
}).then(function () {
jasonsaayman marked this conversation as resolved.
Show resolved Hide resolved
assert.strictEqual(success, false, 'request should not succeed');
assert.strictEqual(failure, true, 'request should fail');
assert.strictEqual(error.code, 'ERR_REQUEST_ABORTED');
assert.strictEqual(error.message, 'error request aborted');
done();
});
}).catch(done);
});
});

});