Browse Source

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: https://github.com/nodejs/node/pull/9344
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
v6.x
Rich Trott 8 years ago
committed by Myles Borins
parent
commit
5e1fd2822e
  1. 32
      test/parallel/test-http-client-readable.js

32
test/parallel/test-http-client-readable.js

@ -1,21 +1,21 @@
'use strict'; 'use strict';
const common = require('../common'); const common = require('../common');
var assert = require('assert'); const assert = require('assert');
var http = require('http'); const http = require('http');
var util = require('util'); const util = require('util');
var Duplex = require('stream').Duplex; const Duplex = require('stream').Duplex;
function FakeAgent() { function FakeAgent() {
http.Agent.call(this); http.Agent.call(this);
} }
util.inherits(FakeAgent, http.Agent); util.inherits(FakeAgent, http.Agent);
FakeAgent.prototype.createConnection = function createConnection() { FakeAgent.prototype.createConnection = function() {
var s = new Duplex(); const s = new Duplex();
var once = false; var once = false;
s._read = function _read() { s._read = function() {
if (once) if (once)
return this.push(null); return this.push(null);
once = true; once = true;
@ -27,11 +27,11 @@ FakeAgent.prototype.createConnection = function createConnection() {
}; };
// Blackhole // Blackhole
s._write = function _write(data, enc, cb) { s._write = function(data, enc, cb) {
cb(); cb();
}; };
s.destroy = s.destroySoon = function destroy() { s.destroy = s.destroySoon = function() {
this.writable = false; this.writable = false;
}; };
@ -40,17 +40,15 @@ FakeAgent.prototype.createConnection = function createConnection() {
var received = ''; var received = '';
var req = http.request({ const req = http.request({
agent: new FakeAgent() agent: new FakeAgent()
}, common.mustCall(function(res) { }, common.mustCall(function requestCallback(res) {
res.on('data', function(chunk) { res.on('data', function dataCallback(chunk) {
received += chunk; received += chunk;
}); });
res.on('end', common.mustCall(function() {})); res.on('end', common.mustCall(function endCallback() {
assert.strictEqual(received, 'hello world');
}));
})); }));
req.end(); req.end();
process.on('exit', function() {
assert.equal(received, 'hello world');
});

Loading…
Cancel
Save