Skip to content

Commit

Permalink
Fix use of stream.write(data, encoding) in tests
Browse files Browse the repository at this point in the history
For several tests I used a shortcut to write an list-of-chunks to a
stream:

    chunks.forEach(stream.write.bind(stream));

This is a quick way to make a function from a method. The problem is
that `forEach` will pass the index of the array item as a second
argument, and `write` has a second argument (buffer) `encoding`. In
Node v15, the encoding is actually checked to see if it's valid -- and
numbers are not valid buffer encodings:

    nodejs/node#33075

The fix is simply to be explicit about which arguments are passed,
rather than relying on the shortcut. This is a little more verbose,
but can still be put in line at least.

Signed-off-by: Michael Bridgen <mikeb@squaremobius.net>
  • Loading branch information
squaremo committed Feb 18, 2021
1 parent 1943ad4 commit 87d5808
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion test/frame.js
Expand Up @@ -123,7 +123,7 @@ suite("Parsing", function() {
bufs.push(defs.encodeMethod(f.id, 0, f.fields));
});

partition(bufs).forEach(input.write.bind(input));
partition(bufs).forEach(function (chunk) { input.write(chunk); });
frames.acceptLoop();
if (ex) throw ex;
return i === t.length;
Expand Down
8 changes: 4 additions & 4 deletions test/mux.js
Expand Up @@ -41,7 +41,7 @@ test("single input", function(done) {
// not 0, it's treated specially by PassThrough for some reason. By
// 'specially' I mean it breaks the stream. See e.g.,
// https://github.com/isaacs/readable-stream/pull/55
data.forEach(input.write.bind(input));
data.forEach(function (chunk) { input.write(chunk); });

readAllObjects(output, function(vals) {
assert.deepEqual(data, vals);
Expand Down Expand Up @@ -75,7 +75,7 @@ test("single input, resuming stream", function(done) {
return val;
}

data.forEach(input.write.bind(input));
data.forEach(function (chunk) { input.write(chunk); });

readAllObjects(output, function(vals) {
assert.deepEqual([1,2,3,4,6,7,8,9], vals);
Expand Down Expand Up @@ -145,13 +145,13 @@ test("unpipe", function(done) {
mux.pipeFrom(input);

schedule(function() {
pipedData.forEach(input.write.bind(input));
pipedData.forEach(function (chunk) { input.write(chunk); });

schedule(function() {
mux.unpipeFrom(input);

schedule(function() {
unpipedData.forEach(input.write.bind(input));
unpipedData.forEach(function(chunk) { input.write(chunk); });
input.end();
schedule(function() {
// exhaust so that 'end' fires
Expand Down

0 comments on commit 87d5808

Please sign in to comment.