Skip to content

Commit

Permalink
Down do 20 failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Jun 1, 2018
1 parent 74193c5 commit f5564d9
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 115 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# readable-stream

***Node-core v10.1.0 streams for userland*** [![Build Status](https://travis-ci.org/nodejs/readable-stream.svg?branch=master)](https://travis-ci.org/nodejs/readable-stream)
***Node-core v10.3.0 streams for userland*** [![Build Status](https://travis-ci.org/nodejs/readable-stream.svg?branch=master)](https://travis-ci.org/nodejs/readable-stream)


[![NPM](https://nodei.co/npm/readable-stream.png?downloads=true&downloadRank=true)](https://nodei.co/npm/readable-stream/)
Expand All @@ -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/v10.1.0/docs/api/stream.html).
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v10.3.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
24 changes: 23 additions & 1 deletion build/test-replacements.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const altForEachImplReplacement = require('./common-replacements').altForEachImp
require('./common-replacements').bufferStaticMethods
, specialForEachReplacment =
require('./common-replacements').specialForEachReplacment
, deepStrictEqual = [
/util\.isDeepStrictEqual/,
'require(\'deep-strict-equal\')'
]


module.exports.all = [
[
Expand Down Expand Up @@ -78,6 +83,7 @@ module.exports['common.js'] = [
, objectKeysReplacement
, altForEachImplReplacement
, altForEachUseReplacement
, deepStrictEqual

, [
/(exports.mustCall[\s\S]*)/m
Expand Down Expand Up @@ -110,7 +116,7 @@ module.exports['common.js'] = [
+ ' knownGlobals.push(DTRACE_NET_SOCKET_WRITE);\n'
+ ' if (global.__coverage__)\n'
+ ' knownGlobals.push(__coverage__);\n'
+ '\'core,__core-js_shared__,Promise,Map,Set,WeakMap,WeakSet,Reflect,System,asap,Observable,regeneratorRuntime,_babelPolyfill\'.split(\',\').filter(function (item) { return typeof global[item] !== undefined}).forEach(function (item) {knownGlobals.push(global[item])})'
+ '\'core,__core-js_shared__,console,Promise,Map,Set,WeakMap,WeakSet,Reflect,System,asap,Observable,regeneratorRuntime,_babelPolyfill\'.split(\',\').filter(function (item) { return typeof global[item] !== undefined}).forEach(function (item) {knownGlobals.push(global[item])})'
+ ' /*</replacement>*/\n\n$1'
]

Expand Down Expand Up @@ -338,6 +344,22 @@ module.exports['test-stream-unpipe-event.js'] = [
]
]

module.exports['test-stream-readable-flow-recursion.js'] = [
deepStrictEqual
]

module.exports['test-stream-readable-with-unimplemented-_read.js'] = [
deepStrictEqual
]

module.exports['test-stream-writable-needdrain-state.js'] = [
deepStrictEqual
]

module.exports['test-stream-readable-setEncoding-null.js'] = [
deepStrictEqual
]

module.exports['test-stream-pipeline.js'] = [
[
/require\('http2'\)/g,
Expand Down
51 changes: 34 additions & 17 deletions errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,43 @@

const codes = {};

function createErrorType(name) {
function E(message) {
if (!Error.captureStackTrace)
this.stack = (new Error()).stack;
else
Error.captureStackTrace(this, this.constructor);
this.message = message;
function createErrorType(code, message, Base) {
if (!Base) {
Base = Error
}
E.prototype = new Error();
E.prototype.name = name;
E.prototype.constructor = E;

codes[name] = E;
function getMessage (arg1, arg2) {
if (typeof message === 'string') {
return message
} else {
return message(arg1, arg2)
}
}

// TODO(mcollina) make this a function
class NodeError extends Base {
constructor (arg1, arg2) {
super(getMessage(arg1, arg2));
}
}

NodeError.prototype.name = Base.name;
NodeError.prototype.code = code;

codes[code] = NodeError;
}

createErrorType('ERR_INVALID_OPT_VALUE');
createErrorType('ERR_INVALID_ARG_TYPE');
createErrorType('ERR_STREAM_PUSH_AFTER_EOF');
createErrorType('ERR_METHOD_NOT_IMPLEMENTED');
createErrorType('ERR_STREAM_PUSH_AFTER_EOF');
createErrorType('ERR_STREAM_PREMATURE_CLOSE');
createErrorType('ERR_INVALID_OPT_VALUE', function (name, value) {
return 'The value "' + value + '" is invalid for option "' + name + '"'
}, TypeError);
createErrorType('ERR_INVALID_ARG_TYPE', 'argument must be of the right type');
createErrorType('ERR_STREAM_PUSH_AFTER_EOF', 'stream-push() after EOF');
createErrorType('ERR_METHOD_NOT_IMPLEMENTED', 'the method is not implemented');
createErrorType('ERR_STREAM_PREMATURE_CLOSE', 'premature close');
createErrorType('ERR_STREAM_DESTROYED', 'the stream was destroyed');
createErrorType('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times');
createErrorType('ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable');
createErrorType('ERR_STREAM_WRITE_AFTER_END', 'write after end');
createErrorType('ERR_STREAM_NULL_VALUES', 'May not write null values to stream', TypeError);

module.exports.codes = codes;
19 changes: 11 additions & 8 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ var _require$codes = require('../errors').codes,
ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;

var ReadableAsyncIterator = require('./internal/streams/async_iterator');

var _require2 = require('../experimentalWarning'),
emitExperimentalWarning = _require2.emitExperimentalWarning;

var StringDecoder;
// Lazy loaded to improve the startup performance.


var StringDecoder = void 0;
var ReadableAsyncIterator = void 0;

util.inherits(Readable, Stream);

Expand Down Expand Up @@ -345,7 +347,8 @@ Readable.prototype.isPaused = function () {
Readable.prototype.setEncoding = function (enc) {
if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
this._readableState.decoder = new StringDecoder(enc);
this._readableState.encoding = enc;
// if setEncoding(null), decoder.encoding equals utf8
this._readableState.encoding = this._readableState.decoder.encoding;
return this;
};

Expand Down Expand Up @@ -804,7 +807,7 @@ Readable.prototype.removeListener = function (ev, fn) {

if (ev === 'readable') {
// We need to check if there is someone still listening to
// to readable and reset the state. However this needs to happen
// readable and reset the state. However this needs to happen
// after readable has been emitted but before I/O (nextTick) to
// support once('readable', fn) cycles. This means that calling
// resume within the same tick will have no
Expand All @@ -816,11 +819,11 @@ Readable.prototype.removeListener = function (ev, fn) {
};

Readable.prototype.removeAllListeners = function (ev) {
var res = Stream.prototype.removeAllListeners.call(this, ev);
var res = Stream.prototype.removeAllListeners.apply(this, arguments);

if (ev === 'readable' || ev === undefined) {
// We need to check if there is someone still listening to
// to readable and reset the state. However this needs to happen
// readable and reset the state. However this needs to happen
// after readable has been emitted but before I/O (nextTick) to
// support once('readable', fn) cycles. This means that calling
// resume within the same tick will have no
Expand Down Expand Up @@ -954,7 +957,7 @@ Readable.prototype.wrap = function (stream) {

Readable.prototype[Symbol.asyncIterator] = function () {
emitExperimentalWarning('Readable[Symbol.asyncIterator]');

if (ReadableAsyncIterator === undefined) ReadableAsyncIterator = require('./internal/streams/async_iterator');
return new ReadableAsyncIterator(this);
};

Expand Down
11 changes: 4 additions & 7 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ function writeAfterEnd(stream, cb) {
// mode the stream is in. Currently this means that `null` is never accepted
// and undefined/non-string values are only allowed in object mode.
function validChunk(stream, state, chunk, cb) {
var valid = true;
var er = false;
var er;

if (chunk === null) {
er = new ERR_STREAM_NULL_VALUES();
Expand All @@ -318,9 +317,9 @@ function validChunk(stream, state, chunk, cb) {
if (er) {
stream.emit('error', er);
pna.nextTick(cb, er);
valid = false;
return false;
}
return valid;
return true;
}

Writable.prototype.write = function (chunk, encoding, cb) {
Expand Down Expand Up @@ -350,9 +349,7 @@ Writable.prototype.write = function (chunk, encoding, cb) {
};

Writable.prototype.cork = function () {
var state = this._writableState;

state.corked++;
this._writableState.corked++;
};

Writable.prototype.uncork = function () {
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/streams/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var pna = require('process-nextick-args');
/*</replacement>*/

var eos = require('./end-of-stream');
var eos = void 0;

var _require$codes = require('../../../errors').codes,
ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS,
Expand Down Expand Up @@ -37,6 +37,7 @@ function destroyer(stream, reading, writing, callback) {
closed = true;
});

if (eos === undefined) eos = require('./end-of-stream');
eos(stream, { readable: reading, writable: writing }, function (err) {
if (err) return callback(err);
closed = true;
Expand Down
17 changes: 9 additions & 8 deletions lib/internal/streams/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ var pna = require('process-nextick-args');

var ERR_INVALID_OPT_VALUE = require('../../../errors').codes.ERR_INVALID_OPT_VALUE;

function highWaterMarkFrom(options, isDuplex, duplexKey) {
return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
}

function getHighWaterMark(state, options, duplexKey, isDuplex) {
var hwm = options.highWaterMark;
var hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
if (hwm != null) {
if (typeof hwm !== 'number' || !(hwm >= 0)) throw new ERR_INVALID_OPT_VALUE('highWaterMark', hwm);
return Math.floor(hwm);
} else if (isDuplex) {
hwm = options[duplexKey];
if (hwm != null) {
if (typeof hwm !== 'number' || !(hwm >= 0)) throw new ERR_INVALID_OPT_VALUE(duplexKey, hwm);
return Math.floor(hwm);
if (!Number.isInteger(hwm) || hwm < 0) {
var name = isDuplex ? duplexKey : 'highWaterMark';
throw new ERR_INVALID_OPT_VALUE(name, hwm);
}
return Math.floor(hwm);
}

// Default value
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"assert": "^1.4.0",
"babel-polyfill": "^6.9.1",
"buffer": "^5.1.0",
"deep-strict-equal": "^0.2.0",
"lolex": "^2.6.0",
"nyc": "^11.0.0",
"tap": "^11.0.0",
Expand Down
5 changes: 0 additions & 5 deletions test/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,6 @@ Attempts to get a valid TTY file descriptor. Returns `-1` if it fails.

The TTY file descriptor is assumed to be capable of being writable.

### globalCheck
* [&lt;boolean>]

Set to `false` if the test should not check for global leaks.

### hasCrypto
* [&lt;boolean>]

Expand Down
38 changes: 4 additions & 34 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,7 @@ exports.platformTimeout = function (ms) {
return ms; // ARMv8+
};

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

if (global.gc) {
knownGlobals.push(global.gc);
Expand All @@ -373,31 +372,6 @@ if (global.COUNTER_NET_SERVER_CONNECTION) {
knownGlobals.push(COUNTER_HTTP_CLIENT_RESPONSE);
}

/*<replacement>*/if (!process.browser) {
if (global.ArrayBuffer) {
knownGlobals.push(ArrayBuffer);
knownGlobals.push(Int8Array);
knownGlobals.push(Uint8Array);
knownGlobals.push(Uint8ClampedArray);
knownGlobals.push(Int16Array);
knownGlobals.push(Uint16Array);
knownGlobals.push(Int32Array);
knownGlobals.push(Uint32Array);
knownGlobals.push(Float32Array);
knownGlobals.push(Float64Array);
knownGlobals.push(DataView);
}
} /*</replacement>*/

// Harmony features.
if (global.Proxy) {
knownGlobals.push(Proxy);
}

if (global.Symbol) {
knownGlobals.push(Symbol);
}

if (process.env.NODE_TEST_KNOWN_GLOBALS) {
var knownFromEnv = process.env.NODE_TEST_KNOWN_GLOBALS.split(',');
allowGlobals.apply(undefined, _toConsumableArray(knownFromEnv));
Expand All @@ -417,7 +391,7 @@ if (typeof constructor == 'function') knownGlobals.push(constructor);
if (typeof DTRACE_NET_SOCKET_READ == 'function') knownGlobals.push(DTRACE_NET_SOCKET_READ);
if (typeof DTRACE_NET_SOCKET_WRITE == 'function') knownGlobals.push(DTRACE_NET_SOCKET_WRITE);
if (global.__coverage__) knownGlobals.push(__coverage__);
'core,__core-js_shared__,Promise,Map,Set,WeakMap,WeakSet,Reflect,System,asap,Observable,regeneratorRuntime,_babelPolyfill'.split(',').filter(function (item) {
'core,__core-js_shared__,console,Promise,Map,Set,WeakMap,WeakSet,Reflect,System,asap,Observable,regeneratorRuntime,_babelPolyfill'.split(',').filter(function (item) {
return typeof global[item] !== undefined;
}).forEach(function (item) {
knownGlobals.push(global[item]);
Expand All @@ -442,11 +416,7 @@ function leakedGlobals() {
}
exports.leakedGlobals = leakedGlobals;

// Turn this off if the test should not check for global leaks.
exports.globalCheck = true;

process.on('exit', function () {
if (!exports.globalCheck) return;
var leaked = leakedGlobals();
if (leaked.length > 0) {
assert.fail('Unexpected global(s) found: ' + leaked.join(', '));
Expand Down Expand Up @@ -820,7 +790,7 @@ exports.expectsError = function expectsError(fn, settings, exact) {
for (var _iterator2 = keys[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var key = _step2.value;

if (!util.isDeepStrictEqual(error[key], innerSettings[key])) {
if (!require('deep-strict-equal')(error[key], innerSettings[key])) {
// Create placeholder objects to create a nice output.
var a = new Comparison(error, keys);
var b = new Comparison(innerSettings, keys);
Expand Down Expand Up @@ -1015,4 +985,4 @@ if (!util._errnoException) {
e.syscall = syscall;
return e;
};
}
}
Loading

0 comments on commit f5564d9

Please sign in to comment.