Skip to content

Commit bbc3ddc

Browse files
authored
Updated to Node 10.10 (#363)
* Updated to Node 10.10 * fix failing test, the code is correct
1 parent 4dc9573 commit bbc3ddc

16 files changed

+421
-233
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ npm install --save readable-stream
1515

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

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

2020
If you want to guarantee a stable streams base, regardless of what version of
2121
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).

lib/_stream_readable.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ function emitReadable(stream) {
512512

513513
function emitReadable_(stream) {
514514
var state = stream._readableState;
515-
debug('emit readable');
515+
debug('emitReadable_', state.destroyed, state.length, state.ended);
516516
if (!state.destroyed && (state.length || state.ended)) {
517517
stream.emit('readable');
518518
}
@@ -767,6 +767,7 @@ Readable.prototype.on = function (ev, fn) {
767767
} else if (ev === 'readable') {
768768
if (!state.endEmitted && !state.readableListening) {
769769
state.readableListening = state.needReadable = true;
770+
state.flowing = false;
770771
state.emittedReadable = false;
771772
debug('on readable', state.length, state.reading);
772773
if (state.length) {
@@ -815,6 +816,11 @@ Readable.prototype.removeAllListeners = function (ev) {
815816

816817
function updateReadableListening(self) {
817818
self._readableState.readableListening = self.listenerCount('readable') > 0;
819+
820+
// crude way to check if we should resume
821+
if (self.listenerCount('data') > 0) {
822+
self.resume();
823+
}
818824
}
819825

820826
function nReadingNextTick(self) {
@@ -829,7 +835,8 @@ Readable.prototype.resume = function () {
829835
if (!state.flowing) {
830836
debug('resume');
831837
// we flow only if there is no one listening
832-
// for readable
838+
// for readable, but we still have to call
839+
// resume()
833840
state.flowing = !state.readableListening;
834841
resume(this, state);
835842
}
@@ -1035,4 +1042,4 @@ function indexOf(xs, x) {
10351042
if (xs[i] === x) return i;
10361043
}
10371044
return -1;
1038-
}
1045+
}

test/browser/test-stream2-unpipe-drain.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ module.exports = function (t) {
5858

5959
dest.on('unpipe', function() {
6060
t.equal(src1.reads, 2);
61-
t.equal(src2.reads, 2);
61+
t.equal(src2.reads, 1);
6262
t.end();
6363
});
6464
});

test/common/README.md

Lines changed: 94 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ tasks.
4242

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

45-
### arrayStream
46-
A stream to push an array into a REPL
47-
4845
### busyLoop(time)
4946
* `time` [<number>]
5047

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

181178
Indicates if there are multiple localhosts available.
182179

183-
### hijackStderr(listener)
184-
* `listener` [<Function>]: a listener with a single parameter
185-
called `data`.
186-
187-
Eavesdrop to `process.stderr.write` calls. Once `process.stderr.write` is
188-
called, `listener` will also be called and the `data` of `write` function will
189-
be passed to `listener`. What's more, `process.stderr.writeTimes` is a count of
190-
the number of calls.
191-
192-
### hijackStdout(listener)
193-
* `listener` [<Function>]: a listener with a single parameter
194-
called `data`.
195-
196-
Eavesdrop to `process.stdout.write` calls. Once `process.stdout.write` is
197-
called, `listener` will also be called and the `data` of `write` function will
198-
be passed to `listener`. What's more, `process.stdout.writeTimes` is a count of
199-
the number of calls.
200-
201180
### inFreeBSDJail
202181
* [<boolean>]
203182

@@ -249,11 +228,6 @@ Platform check for Windows.
249228

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

252-
### isCPPSymbolsNotMapped
253-
* [<boolean>]
254-
255-
Platform check for C++ symbols are mapped or not.
256-
257231
### leakedGlobals()
258232
* return [<Array>]
259233

@@ -321,21 +295,6 @@ otherwise.
321295
### noWarnCode
322296
See `common.expectWarning()` for usage.
323297

324-
### onGC(target, listener)
325-
* `target` [<Object>]
326-
* `listener` [<Object>]
327-
* `ongc` [<Function>]
328-
329-
Installs a GC listener for the collection of `target`.
330-
331-
This uses `async_hooks` for GC tracking. This means that it enables
332-
`async_hooks` tracking, which may affect the test functionality. It also
333-
means that between a `global.gc()` call and the listener being invoked
334-
a full `setImmediate()` invocation passes.
335-
336-
`listener` is an object to make it easier to use a closure; the target object
337-
should not be in scope when `listener.ongc()` is created.
338-
339298
### opensslCli
340299
* [<boolean>]
341300

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

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

365-
### restoreStderr()
366-
367-
Restore the original `process.stderr.write`. Used to restore `stderr` to its
368-
original state after calling [`common.hijackStdErr()`][].
324+
### pwdCommand
325+
* [<array>] First two argument for the `spawn`/`exec` functions.
369326

370-
### restoreStdout()
327+
Platform normalized `pwd` command options. Usage example:
328+
```js
329+
const common = require('../common');
330+
const { spawn } = require('child_process');
371331

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

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

408-
### spawnPwd(options)
409-
* `options` [<Object>]
410-
* return [<Object>]
368+
## ArrayStream Module
411369

412-
Platform normalizes the `pwd` command.
370+
The `ArrayStream` module provides a simple `Stream` that pushes elements from
371+
a given array.
413372

414-
### spawnSyncPwd(options)
415-
* `options` [<Object>]
416-
* return [<Object>]
373+
<!-- eslint-disable no-undef, node-core/required-modules -->
374+
```js
375+
const ArrayStream = require('../common/arraystream');
376+
const stream = new ArrayStream();
377+
stream.run(['a', 'b', 'c']);
378+
```
417379

418-
Synchronous version of `spawnPwd`.
380+
It can be used within tests as a simple mock stream.
419381

420382
## Countdown Module
421383

@@ -589,6 +551,52 @@ validateSnapshotNodes('TLSWRAP', [
589551
]);
590552
```
591553

554+
## hijackstdio Module
555+
556+
The `hijackstdio` module provides utility functions for temporarily redirecting
557+
`stdout` and `stderr` output.
558+
559+
<!-- eslint-disable no-undef, node-core/required-modules -->
560+
```js
561+
const { hijackStdout, restoreStdout } = require('../common/hijackstdio');
562+
563+
hijackStdout((data) => {
564+
/* Do something with data */
565+
restoreStdout();
566+
});
567+
568+
console.log('this is sent to the hijacked listener');
569+
```
570+
571+
### hijackStderr(listener)
572+
* `listener` [&lt;Function>]: a listener with a single parameter
573+
called `data`.
574+
575+
Eavesdrop to `process.stderr.write()` calls. Once `process.stderr.write()` is
576+
called, `listener` will also be called and the `data` of `write` function will
577+
be passed to `listener`. What's more, `process.stderr.writeTimes` is a count of
578+
the number of calls.
579+
580+
### hijackStdout(listener)
581+
* `listener` [&lt;Function>]: a listener with a single parameter
582+
called `data`.
583+
584+
Eavesdrop to `process.stdout.write()` calls. Once `process.stdout.write()` is
585+
called, `listener` will also be called and the `data` of `write` function will
586+
be passed to `listener`. What's more, `process.stdout.writeTimes` is a count of
587+
the number of calls.
588+
589+
### restoreStderr()
590+
591+
Restore the original `process.stderr.write()`. Used to restore `stderr` to its
592+
original state after calling [`hijackstdio.hijackStdErr()`][].
593+
594+
### restoreStdout()
595+
596+
Restore the original `process.stdout.write()`. Used to restore `stdout` to its
597+
original state after calling [`hijackstdio.hijackStdOut()`][].
598+
599+
592600
## HTTP/2 Module
593601

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

745+
## ongc Module
746+
747+
The `ongc` module allows a garbage collection listener to be installed. The
748+
module exports a single `onGC()` function.
749+
750+
```js
751+
require('../common');
752+
const onGC = require('../common/ongc');
753+
754+
onGC({}, { ongc() { console.log('collected'); } });
755+
```
756+
757+
### onGC(target, listener)
758+
* `target` [&lt;Object>]
759+
* `listener` [&lt;Object>]
760+
* `ongc` [&lt;Function>]
761+
762+
Installs a GC listener for the collection of `target`.
763+
764+
This uses `async_hooks` for GC tracking. This means that it enables
765+
`async_hooks` tracking, which may affect the test functionality. It also
766+
means that between a `global.gc()` call and the listener being invoked
767+
a full `setImmediate()` invocation passes.
768+
769+
`listener` is an object to make it easier to use a closure; the target object
770+
should not be in scope when `listener.ongc()` is created.
771+
772+
737773
## tmpdir Module
738774

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

773809
function forEach (xs, f) {

test/common/arraystream.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'use strict';
2+
3+
/*<replacement>*/
4+
require('babel-polyfill');
5+
var util = require('util');
6+
for (var i in util) {
7+
exports[i] = util[i];
8+
} /*</replacement>*/ /* eslint-disable node-core/required-modules */
9+
'use strict';
10+
11+
/*<replacement>*/
12+
var objectKeys = objectKeys || function (obj) {
13+
var keys = [];
14+
for (var key in obj) {
15+
keys.push(key);
16+
}return keys;
17+
};
18+
/*</replacement>*/
19+
20+
var _require = require('../../'),
21+
Stream = _require.Stream;
22+
23+
var _require2 = require('util'),
24+
inherits = _require2.inherits;
25+
26+
function noop() {}
27+
28+
// A stream to push an array into a REPL
29+
function ArrayStream() {
30+
this.run = function (data) {
31+
var _this = this;
32+
33+
forEach(data, function (line) {
34+
_this.emit('data', line + '\n');
35+
});
36+
};
37+
}
38+
39+
inherits(ArrayStream, Stream);
40+
ArrayStream.prototype.readable = true;
41+
ArrayStream.prototype.writable = true;
42+
ArrayStream.prototype.pause = noop;
43+
ArrayStream.prototype.resume = noop;
44+
ArrayStream.prototype.write = noop;
45+
46+
module.exports = ArrayStream;
47+
48+
function forEach(xs, f) {
49+
for (var i = 0, l = xs.length; i < l; i++) {
50+
f(xs[i], i);
51+
}
52+
}

test/common/dns.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function readDomainFromPacket(buffer, offset) {
6161
} else {
6262
// Pointer to another part of the packet.
6363
assert.strictEqual(length & 0xC0, 0xC0);
64-
// eslint-disable-next-line
64+
// eslint-disable-next-line space-infix-ops, space-unary-ops
6565
var pointeeOffset = buffer.readUInt16BE(offset) & ~0xC000;
6666
return {
6767
nread: 2,

0 commit comments

Comments
 (0)