mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
f29762f4dd
Enable linting for the test directory. A number of changes was made so all tests conform the current rules used by lib and src directories. The only exception for tests is that unreachable (dead) code is allowed. test-fs-non-number-arguments-throw had to be excluded from the changes because of a weird issue on Windows CI. PR-URL: https://github.com/nodejs/io.js/pull/1721 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
61 lines
1.1 KiB
JavaScript
61 lines
1.1 KiB
JavaScript
'use strict';
|
|
var common = 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);
|
|
});
|