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

Test revisions #10551

Closed
wants to merge 4 commits into from
Closed
Changes from 2 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
58 changes: 25 additions & 33 deletions test/parallel/test-stream2-readable-wrap.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
'use strict';
require('../common');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

common is undefined because this line has not been changed to const common = require('../common'); So again, there's no way this test can actually run as is.

var assert = require('assert');
const assert = require('assert');
const Readable = require('_stream_readable');
const Writable = require('_stream_writable');
const EE = require('events').EventEmitter;

var Readable = require('_stream_readable');
var Writable = require('_stream_writable');
var EE = require('events').EventEmitter;

var testRuns = 0, completedRuns = 0;
function runTest(highWaterMark, objectMode, produce) {
testRuns++;

var old = new EE();
var r = new Readable({ highWaterMark: highWaterMark,
const old = new EE();
const r = new Readable({ highWaterMark: highWaterMark,
objectMode: objectMode });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation needs to be adjusted here to re-align with the first 'h'.

assert.equal(r, r.wrap(old));
assert.strictEqual(r, r.wrap(old));

var ended = false;
r.on('end', function() {
let ended = false;
Copy link
Contributor

@mscdex mscdex Dec 31, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed completely, along with any references since we're already ensuring 'end' is seen via common.mustCall() right below.

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

old.pause = function() {
console.error('old.pause()');
Expand All @@ -32,14 +29,14 @@ function runTest(highWaterMark, objectMode, produce) {
flow();
};

var flowing;
var chunks = 10;
var oldEnded = false;
var expected = [];
let flowing;
let chunks = 10;
let oldEnded = false;
const expected = [];
function flow() {
flowing = true;
while (flowing && chunks-- > 0) {
var item = produce();
const item = produce();
expected.push(item);
console.log('old.emit', chunks, flowing);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all of these console.* statements.

old.emit('data', item);
Expand All @@ -52,19 +49,18 @@ function runTest(highWaterMark, objectMode, produce) {
}
}

var w = new Writable({ highWaterMark: highWaterMark * 2,
const w = new Writable({ highWaterMark: highWaterMark * 2,
objectMode: objectMode });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation here needs to be adjusted as well.

var written = [];
const written = [];
w._write = function(chunk, encoding, cb) {
console.log('_write', chunk);
written.push(chunk);
setTimeout(cb);
setTimeout(cb, 1000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to 1 instead of 1000? No duration specified defaults to 1ms, so using 1 keeps the behavior identical but makes things more explicit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be 1 instead of 1000.

};

w.on('finish', function() {
completedRuns++;
w.on('finish', common.mustCall(function() {
performAsserts();
});
}));

r.pipe(w);

Expand All @@ -77,14 +73,10 @@ function runTest(highWaterMark, objectMode, produce) {
}
}

runTest(100, false, function() { return Buffer.allocUnsafe(100); });
runTest(10, false, function() { return Buffer.from('xxxxxxxxxx'); });
runTest(1, true, function() { return { foo: 'bar' }; });
runTest(100, false, common.mustCall(function() { return Buffer.allocUnsafe(100); });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a missing ) at the end of this line. This is a syntax error. This file won't run. (It looks the pull request template was deleted. It asks that make -j4 test before submitting the pull request.)

runTest(10, false, common.mustCall(function() { return Buffer.from('xxxxxxxxxx'); }));
runTest(1, true, common.mustCall(function() { return { foo: 'bar' }; }));

var objectChunks = [ 5, 'a', false, 0, '', 'xyz', { x: 4 }, 7, [], 555 ];
runTest(1, true, function() { return objectChunks.shift(); });
const objectChunks = [ 5, 'a', false, 0, '', 'xyz', { x: 4 }, 7, [], 555 ];
runTest(1, true, common.mustCall(function() { return objectChunks.shift(); }));

process.on('exit', function() {
assert.equal(testRuns, completedRuns);
console.log('ok');
});