Skip to content

Commit

Permalink
build for 7.3.0 (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinmetcalf authored Dec 23, 2016
1 parent f239454 commit 509ae40
Show file tree
Hide file tree
Showing 15 changed files with 433 additions and 49 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ npm install --save readable-stream
This package is a mirror of the Streams2 and Streams3 implementations in
Node-core.

Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v7.1.0/docs/api/).
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v7.3.0/docs/api/).

If you want to guarantee a stable streams base, regardless of what version of
Node you, or the users of your libraries are using, use **readable-stream** *only* and avoid the *"stream"* module in Node-core, for background see [this blogpost](http://r.va.gg/2014/06/why-i-dont-use-nodes-core-stream-module.html).
Expand Down
10 changes: 8 additions & 2 deletions build/test-replacements.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ module.exports['common.js'] = [
'{now: function (){}}'
],
[
/exports\.enoughTestCpu/,
'//exports.enoughTestCpu'
/(exports\.enoughTestCpu[^;]+;)/,
'/*$1*/'
],
[
/exports\.buildType/,
Expand Down Expand Up @@ -298,3 +298,9 @@ module.exports['test-stream2-readable-empty-buffer-no-eof.js'] = [
'case 3:\n$1setTimeout(r.read.bind(r, 0), 50);'
]
]
module.exports['test-stream-buffer-list.js'] = [
[
/require\('internal\/streams\/BufferList'\);/,
'require(\'../../lib/internal/streams/BufferList\');'
]
]
29 changes: 12 additions & 17 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ var Timer = { now: function () {} };

var testRoot = process.env.NODE_TEST_DIR ? path.resolve(process.env.NODE_TEST_DIR) : __dirname;

exports.testDir = __dirname;
exports.fixturesDir = path.join(exports.testDir, 'fixtures');
exports.fixturesDir = path.join(__dirname, 'fixtures');
exports.tmpDirName = 'tmp';
// PORT should match the definition in test/testpy/__init__.py.
exports.PORT = +process.env.NODE_COMMON_PORT || 12346;
Expand All @@ -60,7 +59,8 @@ exports.isOSX = process.platform === 'darwin';
exports.enoughTestMem = os.totalmem() > 0x40000000; /* 1 Gb */

var cpus = os.cpus();
//exports.enoughTestCpu = cpus.length > 1 || cpus[0].speed > 999;
/*exports.enoughTestCpu = Array.isArray(cpus) &&
(cpus.length > 1 || cpus[0].speed > 999);*/

exports.rootDir = exports.isWindows ? 'c:\\' : '/';
//exports.buildType = process.config.target_defaults.default_configuration;
Expand Down Expand Up @@ -217,12 +217,6 @@ if (exports.isWindows) {
exports.PIPE = exports.tmpDir + '/test.sock';
}

if (exports.isWindows) {
exports.faketimeCli = false;
} else {
exports.faketimeCli = path.join(__dirname, '..', 'tools', 'faketime', 'src', 'faketime');
}

var ifaces = os.networkInterfaces();
exports.hasIPv6 = objectKeys(ifaces).some(function (name) {
return (/lo/.test(name) && ifaces[name].some(function (info) {
Expand Down Expand Up @@ -296,8 +290,8 @@ exports.platformTimeout = function (ms) {
return ms; // ARMv8+
};

var knownGlobals = [setTimeout, setInterval, setImmediate, clearTimeout, clearInterval, clearImmediate, console, constructor, // Enumerable in V8 3.21.
Buffer, process, global];
var knownGlobals = [Buffer, clearImmediate, clearInterval, clearTimeout, console, constructor, // Enumerable in V8 3.21.
global, process, setImmediate, setInterval, setTimeout];

if (global.gc) {
knownGlobals.push(global.gc);
Expand Down Expand Up @@ -379,7 +373,7 @@ function leakedGlobals() {
var leaked = [];

for (var val in global) {
if (-1 === knownGlobals.indexOf(global[val])) leaked.push(val);
if (!knownGlobals.includes(global[val])) leaked.push(val);
}return leaked;
}
exports.leakedGlobals = leakedGlobals;
Expand All @@ -392,7 +386,7 @@ process.on('exit', function () {
var leaked = leakedGlobals();
if (leaked.length > 0) {
console.error('Unknown globals: %s', leaked);
assert.ok(false, 'Unknown global found');
fail('Unknown global found');
}
});

Expand Down Expand Up @@ -451,9 +445,10 @@ exports.fileExists = function (pathname) {
}
};

exports.fail = function (msg) {
function fail(msg) {
assert.fail(null, null, msg);
};
}
exports.fail = fail;

exports.skip = function (msg) {
console.log('1..0 # Skipped: ' + msg);
Expand Down Expand Up @@ -505,9 +500,9 @@ exports.nodeProcessAborted = function nodeProcessAborted(exitCode, signal) {
// one of them (exit code or signal) needs to be set to one of
// the expected exit codes or signals.
if (signal !== null) {
return expectedSignals.indexOf(signal) > -1;
return expectedSignals.includes(signal);
} else {
return expectedExitCodes.indexOf(exitCode) > -1;
return expectedExitCodes.includes(exitCode);
}
};

Expand Down
25 changes: 7 additions & 18 deletions test/parallel/test-stream-big-push.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
/*</replacement>*/
require('../common');
var common = require('../common');
var assert = require('assert/');
var stream = require('../../');
var str = 'asdfasdfasdfasdfasdf';
Expand All @@ -12,29 +12,25 @@ var r = new stream.Readable({
});

var reads = 0;
var eofed = false;
var ended = false;

r._read = function (n) {
function _read() {
if (reads === 0) {
setTimeout(function () {
r.push(str);
});
}, 1);
reads++;
} else if (reads === 1) {
var ret = r.push(str);
assert.strictEqual(ret, false);
reads++;
} else {
assert(!eofed);
eofed = true;
r.push(null);
}
};
}

r.on('end', function () {
ended = true;
});
r._read = common.mustCall(_read, 3);

r.on('end', common.mustCall(function () {}));

// push some data in to start.
// we've never gotten any read event at this point.
Expand All @@ -56,11 +52,4 @@ r.once('readable', function () {

chunk = r.read();
assert.strictEqual(chunk, null);
});

process.on('exit', function () {
assert(eofed);
assert(ended);
assert.strictEqual(reads, 2);
console.log('ok');
});
29 changes: 29 additions & 0 deletions test/parallel/test-stream-buffer-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Flags: --expose_internals
/*<replacement>*/
var bufferShim = require('buffer-shims');
/*</replacement>*/
require('../common');
var assert = require('assert/');
var BufferList = require('../../lib/internal/streams/BufferList');

// Test empty buffer list.
var emptyList = new BufferList();

emptyList.shift();
assert.deepStrictEqual(emptyList, new BufferList());

assert.strictEqual(emptyList.join(','), '');

assert.deepStrictEqual(emptyList.concat(0), bufferShim.alloc(0));

// Test buffer list with one element.
var list = new BufferList();
list.push('foo');

assert.strictEqual(list.concat(1), 'foo');

assert.strictEqual(list.join(','), 'foo');

var shifted = list.shift();
assert.strictEqual(shifted, 'foo');
assert.deepStrictEqual(list, new BufferList());
3 changes: 3 additions & 0 deletions test/parallel/test-stream-pipe-unpipe-streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ source.unpipe(dest2);
assert.strictEqual(source._readableState.pipes, dest1);
assert.notStrictEqual(source._readableState.pipes, dest2);

dest2.on('unpipe', common.fail);
source.unpipe(dest2);

source.unpipe(dest1);

assert.strictEqual(source._readableState.pipes, null);
72 changes: 72 additions & 0 deletions test/parallel/test-stream-readable-emittedReadable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
/*</replacement>*/
var common = require('../common');
var assert = require('assert/');
var Readable = require('../../').Readable;

var readable = new Readable({
read: function () {}
});

// Initialized to false.
assert.strictEqual(readable._readableState.emittedReadable, false);

readable.on('readable', common.mustCall(function () {
// emittedReadable should be true when the readable event is emitted
assert.strictEqual(readable._readableState.emittedReadable, true);
readable.read();
// emittedReadable is reset to false during read()
assert.strictEqual(readable._readableState.emittedReadable, false);
}, 4));

// When the first readable listener is just attached,
// emittedReadable should be false
assert.strictEqual(readable._readableState.emittedReadable, false);

// Each one of these should trigger a readable event.
process.nextTick(common.mustCall(function () {
readable.push('foo');
}));
process.nextTick(common.mustCall(function () {
readable.push('bar');
}));
process.nextTick(common.mustCall(function () {
readable.push('quo');
}));
process.nextTick(common.mustCall(function () {
readable.push(null);
}));

var noRead = new Readable({
read: function () {}
});

noRead.on('readable', common.mustCall(function () {
// emittedReadable should be true when the readable event is emitted
assert.strictEqual(noRead._readableState.emittedReadable, true);
noRead.read(0);
// emittedReadable is not reset during read(0)
assert.strictEqual(noRead._readableState.emittedReadable, true);
}));

noRead.push('foo');
noRead.push(null);

var flowing = new Readable({
read: function () {}
});

flowing.on('data', common.mustCall(function () {
// When in flowing mode, emittedReadable is always false.
assert.strictEqual(flowing._readableState.emittedReadable, false);
flowing.read();
assert.strictEqual(flowing._readableState.emittedReadable, false);
}, 3));

flowing.push('foooo');
flowing.push('bar');
flowing.push('quo');
process.nextTick(common.mustCall(function () {
flowing.push(null);
}));
98 changes: 98 additions & 0 deletions test/parallel/test-stream-readable-needReadable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
/*</replacement>*/
var common = require('../common');
var assert = require('assert/');
var Readable = require('../../').Readable;

var readable = new Readable({
read: function () {}
});

// Initialized to false.
assert.strictEqual(readable._readableState.needReadable, false);

readable.on('readable', common.mustCall(function () {
// When the readable event fires, needReadable is reset.
assert.strictEqual(readable._readableState.needReadable, false);
readable.read();
}));

// If a readable listener is attached, then a readable event is needed.
assert.strictEqual(readable._readableState.needReadable, true);

readable.push('foo');
readable.push(null);

readable.on('end', common.mustCall(function () {
// No need to emit readable anymore when the stream ends.
assert.strictEqual(readable._readableState.needReadable, false);
}));

var asyncReadable = new Readable({
read: function () {}
});

asyncReadable.on('readable', common.mustCall(function () {
if (asyncReadable.read() !== null) {
// After each read(), the buffer is empty.
// If the stream doesn't end now,
// then we need to notify the reader on future changes.
assert.strictEqual(asyncReadable._readableState.needReadable, true);
}
}, 3));

process.nextTick(common.mustCall(function () {
asyncReadable.push('foooo');
}));
process.nextTick(common.mustCall(function () {
asyncReadable.push('bar');
}));
process.nextTick(common.mustCall(function () {
asyncReadable.push(null);
}));

var flowing = new Readable({
read: function () {}
});

// Notice this must be above the on('data') call.
flowing.push('foooo');
flowing.push('bar');
flowing.push('quo');
process.nextTick(common.mustCall(function () {
flowing.push(null);
}));

// When the buffer already has enough data, and the stream is
// in flowing mode, there is no need for the readable event.
flowing.on('data', common.mustCall(function (data) {
assert.strictEqual(flowing._readableState.needReadable, false);
}, 3));

var slowProducer = new Readable({
read: function () {}
});

slowProducer.on('readable', common.mustCall(function () {
if (slowProducer.read(8) === null) {
// The buffer doesn't have enough data, and the stream is not ened,
// we need to notify the reader when data arrives.
assert.strictEqual(slowProducer._readableState.needReadable, true);
} else {
assert.strictEqual(slowProducer._readableState.needReadable, false);
}
}, 4));

process.nextTick(common.mustCall(function () {
slowProducer.push('foo');
}));
process.nextTick(common.mustCall(function () {
slowProducer.push('foo');
}));
process.nextTick(common.mustCall(function () {
slowProducer.push('foo');
}));
process.nextTick(common.mustCall(function () {
slowProducer.push(null);
}));
Loading

0 comments on commit 509ae40

Please sign in to comment.