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

Updated to Node 10.10 #363

Merged
merged 2 commits into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ npm install --save readable-stream

This package is a mirror of the streams implementations in Node.js.

Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v10.9.0/docs/api/stream.html).
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v10.10.0/docs/api/stream.html).

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
13 changes: 10 additions & 3 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ function emitReadable(stream) {

function emitReadable_(stream) {
var state = stream._readableState;
debug('emit readable');
debug('emitReadable_', state.destroyed, state.length, state.ended);
if (!state.destroyed && (state.length || state.ended)) {
stream.emit('readable');
}
Expand Down Expand Up @@ -767,6 +767,7 @@ Readable.prototype.on = function (ev, fn) {
} else if (ev === 'readable') {
if (!state.endEmitted && !state.readableListening) {
state.readableListening = state.needReadable = true;
state.flowing = false;
state.emittedReadable = false;
debug('on readable', state.length, state.reading);
if (state.length) {
Expand Down Expand Up @@ -815,6 +816,11 @@ Readable.prototype.removeAllListeners = function (ev) {

function updateReadableListening(self) {
self._readableState.readableListening = self.listenerCount('readable') > 0;

// crude way to check if we should resume
if (self.listenerCount('data') > 0) {
self.resume();
}
}

function nReadingNextTick(self) {
Expand All @@ -829,7 +835,8 @@ Readable.prototype.resume = function () {
if (!state.flowing) {
debug('resume');
// we flow only if there is no one listening
// for readable
// for readable, but we still have to call
// resume()
state.flowing = !state.readableListening;
resume(this, state);
}
Expand Down Expand Up @@ -1035,4 +1042,4 @@ function indexOf(xs, x) {
if (xs[i] === x) return i;
}
return -1;
}
}
2 changes: 1 addition & 1 deletion test/browser/test-stream2-unpipe-drain.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module.exports = function (t) {

dest.on('unpipe', function() {
t.equal(src1.reads, 2);
t.equal(src2.reads, 2);
t.equal(src2.reads, 1);
t.end();
});
});
Expand Down
152 changes: 94 additions & 58 deletions test/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ tasks.

Takes `whitelist` and concats that with predefined `knownGlobals`.

### arrayStream
A stream to push an array into a REPL

### busyLoop(time)
* `time` [<number>]

Expand Down Expand Up @@ -180,24 +177,6 @@ Indicates whether `IPv6` is supported on this platform.

Indicates if there are multiple localhosts available.

### hijackStderr(listener)
* `listener` [<Function>]: a listener with a single parameter
called `data`.

Eavesdrop to `process.stderr.write` calls. Once `process.stderr.write` is
called, `listener` will also be called and the `data` of `write` function will
be passed to `listener`. What's more, `process.stderr.writeTimes` is a count of
the number of calls.

### hijackStdout(listener)
* `listener` [<Function>]: a listener with a single parameter
called `data`.

Eavesdrop to `process.stdout.write` calls. Once `process.stdout.write` is
called, `listener` will also be called and the `data` of `write` function will
be passed to `listener`. What's more, `process.stdout.writeTimes` is a count of
the number of calls.

### inFreeBSDJail
* [<boolean>]

Expand Down Expand Up @@ -249,11 +228,6 @@ Platform check for Windows.

Platform check for Windows 32-bit on Windows 64-bit.

### isCPPSymbolsNotMapped
* [<boolean>]

Platform check for C++ symbols are mapped or not.

### leakedGlobals()
* return [<Array>]

Expand Down Expand Up @@ -321,21 +295,6 @@ otherwise.
### noWarnCode
See `common.expectWarning()` for usage.

### onGC(target, listener)
* `target` [<Object>]
* `listener` [<Object>]
* `ongc` [<Function>]

Installs a GC listener for the collection of `target`.

This uses `async_hooks` for GC tracking. This means that it enables
`async_hooks` tracking, which may affect the test functionality. It also
means that between a `global.gc()` call and the listener being invoked
a full `setImmediate()` invocation passes.

`listener` is an object to make it easier to use a closure; the target object
should not be in scope when `listener.ongc()` is created.

### opensslCli
* [<boolean>]

Expand All @@ -362,15 +321,16 @@ A port number for tests to use if one is needed.

Logs '1..0 # Skipped: ' + `msg`

### restoreStderr()

Restore the original `process.stderr.write`. Used to restore `stderr` to its
original state after calling [`common.hijackStdErr()`][].
### pwdCommand
* [<array>] First two argument for the `spawn`/`exec` functions.

### restoreStdout()
Platform normalized `pwd` command options. Usage example:
```js
const common = require('../common');
const { spawn } = require('child_process');

Restore the original `process.stdout.write`. Used to restore `stdout` to its
original state after calling [`common.hijackStdOut()`][].
spawn(...common.pwdCommand, { stdio: ['pipe'] });
```

### rootDir
* [<string>]
Expand Down Expand Up @@ -405,17 +365,19 @@ was disabled at compile time.
Skip the rest of the tests in the current file when the Node.js executable
was compiled with a pointer size smaller than 64 bits.

### spawnPwd(options)
* `options` [<Object>]
* return [<Object>]
## ArrayStream Module

Platform normalizes the `pwd` command.
The `ArrayStream` module provides a simple `Stream` that pushes elements from
a given array.

### spawnSyncPwd(options)
* `options` [<Object>]
* return [<Object>]
<!-- eslint-disable no-undef, node-core/required-modules -->
```js
const ArrayStream = require('../common/arraystream');
const stream = new ArrayStream();
stream.run(['a', 'b', 'c']);
```

Synchronous version of `spawnPwd`.
It can be used within tests as a simple mock stream.

## Countdown Module

Expand Down Expand Up @@ -589,6 +551,52 @@ validateSnapshotNodes('TLSWRAP', [
]);
```

## hijackstdio Module

The `hijackstdio` module provides utility functions for temporarily redirecting
`stdout` and `stderr` output.

<!-- eslint-disable no-undef, node-core/required-modules -->
```js
const { hijackStdout, restoreStdout } = require('../common/hijackstdio');

hijackStdout((data) => {
/* Do something with data */
restoreStdout();
});

console.log('this is sent to the hijacked listener');
```

### hijackStderr(listener)
* `listener` [&lt;Function>]: a listener with a single parameter
called `data`.

Eavesdrop to `process.stderr.write()` calls. Once `process.stderr.write()` is
called, `listener` will also be called and the `data` of `write` function will
be passed to `listener`. What's more, `process.stderr.writeTimes` is a count of
the number of calls.

### hijackStdout(listener)
* `listener` [&lt;Function>]: a listener with a single parameter
called `data`.

Eavesdrop to `process.stdout.write()` calls. Once `process.stdout.write()` is
called, `listener` will also be called and the `data` of `write` function will
be passed to `listener`. What's more, `process.stdout.writeTimes` is a count of
the number of calls.

### restoreStderr()

Restore the original `process.stderr.write()`. Used to restore `stderr` to its
original state after calling [`hijackstdio.hijackStdErr()`][].

### restoreStdout()

Restore the original `process.stdout.write()`. Used to restore `stdout` to its
original state after calling [`hijackstdio.hijackStdOut()`][].


## HTTP/2 Module

The http2.js module provides a handful of utilities for creating mock HTTP/2
Expand Down Expand Up @@ -734,6 +742,34 @@ via `NODE_TEST_*` environment variables. For example, to configure
`internet.addresses.INET_HOST`, set the environment
variable `NODE_TEST_INET_HOST` to a specified host.

## ongc Module

The `ongc` module allows a garbage collection listener to be installed. The
module exports a single `onGC()` function.

```js
require('../common');
const onGC = require('../common/ongc');

onGC({}, { ongc() { console.log('collected'); } });
```

### onGC(target, listener)
* `target` [&lt;Object>]
* `listener` [&lt;Object>]
* `ongc` [&lt;Function>]

Installs a GC listener for the collection of `target`.

This uses `async_hooks` for GC tracking. This means that it enables
`async_hooks` tracking, which may affect the test functionality. It also
means that between a `global.gc()` call and the listener being invoked
a full `setImmediate()` invocation passes.

`listener` is an object to make it easier to use a closure; the target object
should not be in scope when `listener.ongc()` is created.


## tmpdir Module

The `tmpdir` module supports the use of a temporary directory for testing.
Expand Down Expand Up @@ -766,8 +802,8 @@ implementation with tests from
[&lt;boolean>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type
[&lt;number>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type
[&lt;string>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type
[`common.hijackStdErr()`]: #hijackstderrlistener
[`common.hijackStdOut()`]: #hijackstdoutlistener
[`hijackstdio.hijackStdErr()`]: #hijackstderrlistener
[`hijackstdio.hijackStdOut()`]: #hijackstdoutlistener
[internationalization]: https://github.com/nodejs/node/wiki/Intl

function forEach (xs, f) {
Expand Down
52 changes: 52 additions & 0 deletions test/common/arraystream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict';

/*<replacement>*/
require('babel-polyfill');
var util = require('util');
for (var i in util) {
exports[i] = util[i];
} /*</replacement>*/ /* eslint-disable node-core/required-modules */
'use strict';

/*<replacement>*/
var objectKeys = objectKeys || function (obj) {
var keys = [];
for (var key in obj) {
keys.push(key);
}return keys;
};
/*</replacement>*/

var _require = require('../../'),
Stream = _require.Stream;

var _require2 = require('util'),
inherits = _require2.inherits;

function noop() {}

// A stream to push an array into a REPL
function ArrayStream() {
this.run = function (data) {
var _this = this;

forEach(data, function (line) {
_this.emit('data', line + '\n');
});
};
}

inherits(ArrayStream, Stream);
ArrayStream.prototype.readable = true;
ArrayStream.prototype.writable = true;
ArrayStream.prototype.pause = noop;
ArrayStream.prototype.resume = noop;
ArrayStream.prototype.write = noop;

module.exports = ArrayStream;

function forEach(xs, f) {
for (var i = 0, l = xs.length; i < l; i++) {
f(xs[i], i);
}
}
2 changes: 1 addition & 1 deletion test/common/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function readDomainFromPacket(buffer, offset) {
} else {
// Pointer to another part of the packet.
assert.strictEqual(length & 0xC0, 0xC0);
// eslint-disable-next-line
// eslint-disable-next-line space-infix-ops, space-unary-ops
var pointeeOffset = buffer.readUInt16BE(offset) & ~0xC000;
return {
nread: 2,
Expand Down
Loading