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

test: refactor test-http-client-readable #9344

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions test/parallel/test-http-client-readable.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
'use strict';
const common = require('../common');
var assert = require('assert');
var http = require('http');
var util = require('util');
const assert = require('assert');
const http = require('http');
const util = require('util');

var Duplex = require('stream').Duplex;
const Duplex = require('stream').Duplex;

function FakeAgent() {
http.Agent.call(this);
}
util.inherits(FakeAgent, http.Agent);

FakeAgent.prototype.createConnection = function createConnection() {
var s = new Duplex();
FakeAgent.prototype.createConnection = function() {
const s = new Duplex();
var once = false;

s._read = function _read() {
s._read = function() {
if (once)
return this.push(null);
once = true;
Expand All @@ -27,11 +27,11 @@ FakeAgent.prototype.createConnection = function createConnection() {
};

// Blackhole
s._write = function _write(data, enc, cb) {
s._write = function(data, enc, cb) {
cb();
};

s.destroy = s.destroySoon = function destroy() {
s.destroy = s.destroySoon = function() {
this.writable = false;
};

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

var received = '';

var req = http.request({
const req = http.request({
agent: new FakeAgent()
}, common.mustCall(function(res) {
res.on('data', function(chunk) {
}, common.mustCall(function requestCallback(res) {
res.on('data', function dataCallback(chunk) {
received += chunk;
});

res.on('end', common.mustCall(function() {}));
res.on('end', common.mustCall(function endCallback() {
assert.strictEqual(received, 'hello world');
}));
}));
req.end();

process.on('exit', function() {
assert.equal(received, 'hello world');
});