Skip to content

Commit 5e1fd28

Browse files
TrottMyles Borins
authored and
Myles Borins
committed
test: refactor test-http-client-readable
* var -> const * remove function names where V8 inference is as good or better * add function names where there is no V8 inference * assert.equal -> strictEqual * move assertion from exit handler to response end handler PR-URL: #9344 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent c31fa24 commit 5e1fd28

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed
+15-17
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
'use strict';
22
const common = require('../common');
3-
var assert = require('assert');
4-
var http = require('http');
5-
var util = require('util');
3+
const assert = require('assert');
4+
const http = require('http');
5+
const util = require('util');
66

7-
var Duplex = require('stream').Duplex;
7+
const Duplex = require('stream').Duplex;
88

99
function FakeAgent() {
1010
http.Agent.call(this);
1111
}
1212
util.inherits(FakeAgent, http.Agent);
1313

14-
FakeAgent.prototype.createConnection = function createConnection() {
15-
var s = new Duplex();
14+
FakeAgent.prototype.createConnection = function() {
15+
const s = new Duplex();
1616
var once = false;
1717

18-
s._read = function _read() {
18+
s._read = function() {
1919
if (once)
2020
return this.push(null);
2121
once = true;
@@ -27,11 +27,11 @@ FakeAgent.prototype.createConnection = function createConnection() {
2727
};
2828

2929
// Blackhole
30-
s._write = function _write(data, enc, cb) {
30+
s._write = function(data, enc, cb) {
3131
cb();
3232
};
3333

34-
s.destroy = s.destroySoon = function destroy() {
34+
s.destroy = s.destroySoon = function() {
3535
this.writable = false;
3636
};
3737

@@ -40,17 +40,15 @@ FakeAgent.prototype.createConnection = function createConnection() {
4040

4141
var received = '';
4242

43-
var req = http.request({
43+
const req = http.request({
4444
agent: new FakeAgent()
45-
}, common.mustCall(function(res) {
46-
res.on('data', function(chunk) {
45+
}, common.mustCall(function requestCallback(res) {
46+
res.on('data', function dataCallback(chunk) {
4747
received += chunk;
4848
});
4949

50-
res.on('end', common.mustCall(function() {}));
50+
res.on('end', common.mustCall(function endCallback() {
51+
assert.strictEqual(received, 'hello world');
52+
}));
5153
}));
5254
req.end();
53-
54-
process.on('exit', function() {
55-
assert.equal(received, 'hello world');
56-
});

0 commit comments

Comments
 (0)