node/test/parallel/test-http-client-readable.js
Rich Trott 082cc8d6d8 test: remove unnecessary assignments
common.js needs to be loaded in all tests so that there is checking
for variable leaks and possibly other things. However, it does not
need to be assigned to a variable if nothing in common.js is referred
to elsewhere in the test.

PR-URL: https://github.com/nodejs/node/pull/4408
Reviewed-By: James M Snell <jasnell@gmail.com>
2015-12-26 18:00:02 -08:00

61 lines
1.1 KiB
JavaScript

'use strict';
require('../common');
var assert = require('assert');
var http = require('http');
var util = require('util');
var Duplex = require('stream').Duplex;
function FakeAgent() {
http.Agent.call(this);
}
util.inherits(FakeAgent, http.Agent);
FakeAgent.prototype.createConnection = function createConnection() {
var s = new Duplex();
var once = false;
s._read = function read() {
if (once)
return this.push(null);
once = true;
this.push('HTTP/1.1 200 Ok\r\nTransfer-Encoding: chunked\r\n\r\n');
this.push('b\r\nhello world\r\n');
this.readable = false;
this.push('0\r\n\r\n');
};
// Blackhole
s._write = function write(data, enc, cb) {
cb();
};
s.destroy = s.destroySoon = function destroy() {
this.writable = false;
};
return s;
};
var received = '';
var ended = 0;
var req = http.request({
agent: new FakeAgent()
}, function(res) {
res.on('data', function(chunk) {
received += chunk;
});
res.on('end', function() {
ended++;
});
});
req.end();
process.on('exit', function() {
assert.equal(received, 'hello world');
assert.equal(ended, 1);
});