Browse Source

test: remove node-tap lookalike

This commit removes the small node-tap lookalike from several
of the streams2 tests. It's only used by six tests, and is
inconsistent with all other tests.

PR-URL: https://github.com/nodejs/node/pull/13707
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
v6
cjihrig 8 years ago
parent
commit
d3c668cead
  1. 282
      test/parallel/test-stream2-basic.js
  2. 176
      test/parallel/test-stream2-objects.js
  3. 69
      test/parallel/test-stream2-readable-from-list.js
  4. 146
      test/parallel/test-stream2-set-encoding.js
  5. 338
      test/parallel/test-stream2-transform.js
  6. 260
      test/parallel/test-stream2-writable.js

282
test/parallel/test-stream2-basic.js

@ -87,42 +87,8 @@ TestWriter.prototype.end = function(c) {
this.emit('end', this.received);
};
////////
// tiny node-tap lookalike.
const tests = [];
let count = 0;
function test(name, fn) {
count++;
tests.push([name, fn]);
}
function run() {
const next = tests.shift();
if (!next)
return console.error('ok');
const name = next[0];
const fn = next[1];
console.log('# %s', name);
fn({
end: function() {
count--;
run();
}
});
}
// ensure all tests have run
process.on('exit', function() {
assert.strictEqual(count, 0);
});
process.nextTick(run);
test('a most basic test', function(t) {
{
// Test basic functionality
const r = new TestReader(20);
const reads = [];
@ -143,10 +109,9 @@ test('a most basic test', function(t) {
'xxxxxxxxxxxxxxxxxxxxxxxxx',
'xxxxxxxxxxxxxxxxxxxxx' ];
r.on('end', function() {
r.on('end', common.mustCall(function() {
assert.deepStrictEqual(reads, expect);
t.end();
});
}));
let readSize = 1;
function flow() {
@ -158,9 +123,10 @@ test('a most basic test', function(t) {
}
flow();
});
}
test('pipe', function(t) {
{
// Verify pipe
const r = new TestReader(5);
const expect = [ 'xxxxx',
@ -176,72 +142,64 @@ test('pipe', function(t) {
const w = new TestWriter();
w.on('end', function(received) {
w.on('end', common.mustCall(function(received) {
assert.deepStrictEqual(received, expect);
t.end();
});
}));
r.pipe(w);
});
}
[1, 2, 3, 4, 5, 6, 7, 8, 9].forEach(function(SPLIT) {
test('unpipe', function(t) {
const r = new TestReader(5);
// Verify unpipe
const r = new TestReader(5);
// unpipe after 3 writes, then write to another stream instead.
let expect = [ 'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx' ];
expect = [ expect.slice(0, SPLIT), expect.slice(SPLIT) ];
const w = [ new TestWriter(), new TestWriter() ];
let writes = SPLIT;
w[0].on('write', function() {
if (--writes === 0) {
r.unpipe();
assert.strictEqual(r._readableState.pipes, null);
w[0].end();
r.pipe(w[1]);
assert.strictEqual(r._readableState.pipes, w[1]);
}
});
// unpipe after 3 writes, then write to another stream instead.
let expect = [ 'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx' ];
expect = [ expect.slice(0, SPLIT), expect.slice(SPLIT) ];
let ended = 0;
const w = [ new TestWriter(), new TestWriter() ];
let ended0 = false;
let ended1 = false;
w[0].on('end', function(results) {
assert.strictEqual(ended0, false);
ended0 = true;
ended++;
assert.deepStrictEqual(results, expect[0]);
});
let writes = SPLIT;
w[0].on('write', function() {
if (--writes === 0) {
r.unpipe();
assert.strictEqual(r._readableState.pipes, null);
w[0].end();
r.pipe(w[1]);
assert.strictEqual(r._readableState.pipes, w[1]);
}
});
w[1].on('end', function(results) {
assert.strictEqual(ended1, false);
ended1 = true;
ended++;
assert.strictEqual(ended, 2);
assert.deepStrictEqual(results, expect[1]);
t.end();
});
let ended = 0;
r.pipe(w[0]);
});
w[0].on('end', common.mustCall(function(results) {
ended++;
assert.strictEqual(ended, 1);
assert.deepStrictEqual(results, expect[0]);
}));
w[1].on('end', common.mustCall(function(results) {
ended++;
assert.strictEqual(ended, 2);
assert.deepStrictEqual(results, expect[1]);
}));
r.pipe(w[0]);
});
// both writers should get the same exact data.
test('multipipe', function(t) {
{
// Verify both writers get the same data when piping to destinations
const r = new TestReader(5);
const w = [ new TestWriter(), new TestWriter() ];
@ -256,69 +214,66 @@ test('multipipe', function(t) {
'xxxxx',
'xxxxx' ];
let c = 2;
w[0].on('end', function(received) {
w[0].on('end', common.mustCall(function(received) {
assert.deepStrictEqual(received, expect, 'first');
if (--c === 0) t.end();
});
w[1].on('end', function(received) {
}));
w[1].on('end', common.mustCall(function(received) {
assert.deepStrictEqual(received, expect, 'second');
if (--c === 0) t.end();
});
}));
r.pipe(w[0]);
r.pipe(w[1]);
});
}
[1, 2, 3, 4, 5, 6, 7, 8, 9].forEach(function(SPLIT) {
test('multi-unpipe', function(t) {
const r = new TestReader(5);
// unpipe after 3 writes, then write to another stream instead.
let expect = [ 'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx' ];
expect = [ expect.slice(0, SPLIT), expect.slice(SPLIT) ];
// Verify multi-unpipe
const r = new TestReader(5);
const w = [ new TestWriter(), new TestWriter(), new TestWriter() ];
// unpipe after 3 writes, then write to another stream instead.
let expect = [ 'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx',
'xxxxx' ];
expect = [ expect.slice(0, SPLIT), expect.slice(SPLIT) ];
const w = [ new TestWriter(), new TestWriter(), new TestWriter() ];
let writes = SPLIT;
w[0].on('write', function() {
if (--writes === 0) {
r.unpipe();
w[0].end();
r.pipe(w[1]);
}
});
let writes = SPLIT;
w[0].on('write', function() {
if (--writes === 0) {
r.unpipe();
w[0].end();
r.pipe(w[1]);
}
});
let ended = 0;
let ended = 0;
w[0].on('end', common.mustCall(function(results) {
ended++;
assert.strictEqual(ended, 1);
assert.deepStrictEqual(results, expect[0]);
}));
w[0].on('end', function(results) {
ended++;
assert.deepStrictEqual(results, expect[0]);
});
w[1].on('end', common.mustCall(function(results) {
ended++;
assert.strictEqual(ended, 2);
assert.deepStrictEqual(results, expect[1]);
}));
w[1].on('end', function(results) {
ended++;
assert.strictEqual(ended, 2);
assert.deepStrictEqual(results, expect[1]);
t.end();
});
r.pipe(w[0]);
r.pipe(w[2]);
});
r.pipe(w[0]);
r.pipe(w[2]);
});
test('back pressure respected', function(t) {
{
// Verify that back pressure is respected
const r = new R({ objectMode: true });
r._read = common.mustNotCall();
let counter = 0;
@ -330,7 +285,6 @@ test('back pressure respected', function(t) {
const w1 = new R();
w1.write = function(chunk) {
console.error('w1.emit("close")');
assert.strictEqual(chunk[0], 'one');
w1.emit('close');
process.nextTick(function() {
@ -346,7 +300,6 @@ test('back pressure respected', function(t) {
const w2 = new R();
w2.write = function(chunk) {
console.error('w2 write', chunk, counter);
assert.strictEqual(chunk[0], expected.shift());
assert.strictEqual(counter, 0);
@ -358,7 +311,6 @@ test('back pressure respected', function(t) {
setTimeout(function() {
counter--;
console.error('w2 drain');
w2.emit('drain');
}, 10);
@ -368,7 +320,6 @@ test('back pressure respected', function(t) {
const w3 = new R();
w3.write = function(chunk) {
console.error('w3 write', chunk, counter);
assert.strictEqual(chunk[0], expected.shift());
assert.strictEqual(counter, 1);
@ -380,20 +331,19 @@ test('back pressure respected', function(t) {
setTimeout(function() {
counter--;
console.error('w3 drain');
w3.emit('drain');
}, 50);
return false;
};
w3.end = function() {
w3.end = common.mustCall(function() {
assert.strictEqual(counter, 2);
assert.strictEqual(expected.length, 0);
t.end();
};
});
});
}
test('read(0) for ended streams', function(t) {
{
// Verify read(0) behavior for ended streams
const r = new R();
let written = false;
let ended = false;
@ -414,16 +364,16 @@ test('read(0) for ended streams', function(t) {
assert.strictEqual(buffer.toString(), 'foo');
};
w.end = function() {
w.end = common.mustCall(function() {
ended = true;
assert.strictEqual(written, true);
t.end();
};
});
r.pipe(w);
});
}
test('sync _read ending', function(t) {
{
// Verify synchronous _read ending
const r = new R();
let called = false;
r._read = function(n) {
@ -431,6 +381,7 @@ test('sync _read ending', function(t) {
};
r.once('end', function() {
// Verify that this is called before the next tick
called = true;
});
@ -438,11 +389,11 @@ test('sync _read ending', function(t) {
process.nextTick(function() {
assert.strictEqual(called, true);
t.end();
});
});
}
test('adding readable triggers data flow', function(t) {
{
// Verify that adding readable listeners trigger data flow
const r = new R({ highWaterMark: 5 });
let onReadable = false;
let readCalled = 0;
@ -459,17 +410,16 @@ test('adding readable triggers data flow', function(t) {
r.read();
});
r.on('end', function() {
r.on('end', common.mustCall(function() {
assert.strictEqual(readCalled, 3);
assert.ok(onReadable);
t.end();
});
});
}));
}
test('chainable', function(t) {
{
// Verify that streams are chainable
const r = new R();
r._read = common.mustCall();
const r2 = r.setEncoding('utf8').pause().resume().pause();
assert.strictEqual(r, r2);
t.end();
});
}

176
test/parallel/test-stream2-objects.js

@ -26,40 +26,6 @@ const Readable = require('_stream_readable');
const Writable = require('_stream_writable');
const assert = require('assert');
// tiny node-tap lookalike.
const tests = [];
let count = 0;
function test(name, fn) {
count++;
tests.push([name, fn]);
}
function run() {
const next = tests.shift();
if (!next)
return console.error('ok');
const name = next[0];
const fn = next[1];
console.log('# %s', name);
fn({
same: assert.deepStrictEqual,
equal: assert.strictEqual,
end: function() {
count--;
run();
}
});
}
// ensure all tests have run
process.on('exit', function() {
assert.strictEqual(count, 0);
});
process.nextTick(run);
function toArray(callback) {
const stream = new Writable({ objectMode: true });
const list = [];
@ -67,9 +33,9 @@ function toArray(callback) {
list.push(chunk);
};
stream.end = function() {
stream.end = common.mustCall(function() {
callback(list);
};
});
return stream;
}
@ -85,7 +51,8 @@ function fromArray(list) {
return r;
}
test('can read objects from stream', function(t) {
{
// Verify that objects can be read from the stream
const r = fromArray([{ one: '1'}, { two: '2' }]);
const v1 = r.read();
@ -95,34 +62,30 @@ test('can read objects from stream', function(t) {
assert.deepStrictEqual(v1, { one: '1' });
assert.deepStrictEqual(v2, { two: '2' });
assert.deepStrictEqual(v3, null);
}
t.end();
});
test('can pipe objects into stream', function(t) {
{
// Verify that objects can be piped into the stream
const r = fromArray([{ one: '1'}, { two: '2' }]);
r.pipe(toArray(function(list) {
r.pipe(toArray(common.mustCall(function(list) {
assert.deepStrictEqual(list, [
{ one: '1' },
{ two: '2' }
]);
})));
}
t.end();
}));
});
test('read(n) is ignored', function(t) {
{
// Verify that read(n) is ignored
const r = fromArray([{ one: '1'}, { two: '2' }]);
const value = r.read(2);
assert.deepStrictEqual(value, { one: '1' });
}
t.end();
});
test('can read objects from _read (sync)', function(t) {
{
// Verify that objects can be synchronously read
const r = new Readable({ objectMode: true });
const list = [{ one: '1'}, { two: '2' }];
r._read = function(n) {
@ -130,17 +93,16 @@ test('can read objects from _read (sync)', function(t) {
r.push(item || null);
};
r.pipe(toArray(function(list) {
r.pipe(toArray(common.mustCall(function(list) {
assert.deepStrictEqual(list, [
{ one: '1' },
{ two: '2' }
]);
})));
}
t.end();
}));
});
test('can read objects from _read (async)', function(t) {
{
// Verify that objects can be asynchronously read
const r = new Readable({ objectMode: true });
const list = [{ one: '1'}, { two: '2' }];
r._read = function(n) {
@ -150,17 +112,16 @@ test('can read objects from _read (async)', function(t) {
});
};
r.pipe(toArray(function(list) {
r.pipe(toArray(common.mustCall(function(list) {
assert.deepStrictEqual(list, [
{ one: '1' },
{ two: '2' }
]);
})));
}
t.end();
}));
});
test('can read strings as objects', function(t) {
{
// Verify that strings can be read as objects
const r = new Readable({
objectMode: true
});
@ -171,14 +132,13 @@ test('can read strings as objects', function(t) {
});
r.push(null);
r.pipe(toArray(function(array) {
r.pipe(toArray(common.mustCall(function(array) {
assert.deepStrictEqual(array, list);
})));
}
t.end();
}));
});
test('read(0) for object streams', function(t) {
{
// Verify read(0) behavior for object streams
const r = new Readable({
objectMode: true
});
@ -187,14 +147,13 @@ test('read(0) for object streams', function(t) {
r.push('foobar');
r.push(null);
r.pipe(toArray(function(array) {
r.pipe(toArray(common.mustCall(function(array) {
assert.deepStrictEqual(array, ['foobar']);
})));
}
t.end();
}));
});
test('falsey values', function(t) {
{
// Verify the behavior of pushing falsey values
const r = new Readable({
objectMode: true
});
@ -205,14 +164,13 @@ test('falsey values', function(t) {
r.push('');
r.push(null);
r.pipe(toArray(function(array) {
r.pipe(toArray(common.mustCall(function(array) {
assert.deepStrictEqual(array, [false, 0, '']);
})));
}
t.end();
}));
});
test('high watermark _read', function(t) {
{
// Verify high watermark _read() behavior
const r = new Readable({
highWaterMark: 6,
objectMode: true
@ -240,11 +198,10 @@ test('high watermark _read', function(t) {
assert.strictEqual(v3, '3');
assert.strictEqual(calls, 1);
}
t.end();
});
test('high watermark push', function(t) {
{
// Verify high watermark push behavior
const r = new Readable({
highWaterMark: 6,
objectMode: true
@ -254,11 +211,10 @@ test('high watermark push', function(t) {
const bool = r.push(i);
assert.strictEqual(bool, i !== 5);
}
}
t.end();
});
test('can write objects to stream', function(t) {
{
// Verify that objects can be written to stream
const w = new Writable({ objectMode: true });
w._write = function(chunk, encoding, cb) {
@ -266,15 +222,13 @@ test('can write objects to stream', function(t) {
cb();
};
w.on('finish', function() {
t.end();
});
w.on('finish', common.mustCall());
w.write({ foo: 'bar' });
w.end();
});
}
test('can write multiple objects to stream', function(t) {
{
// Verify that multiple objects can be written to stream
const w = new Writable({ objectMode: true });
const list = [];
@ -283,11 +237,9 @@ test('can write multiple objects to stream', function(t) {
cb();
};
w.on('finish', function() {
w.on('finish', common.mustCall(function() {
assert.deepStrictEqual(list, [0, 1, 2, 3, 4]);
t.end();
});
}));
w.write(0);
w.write(1);
@ -295,9 +247,10 @@ test('can write multiple objects to stream', function(t) {
w.write(3);
w.write(4);
w.end();
});
}
test('can write strings as objects', function(t) {
{
// Verify that strings can be written as objects
const w = new Writable({
objectMode: true
});
@ -308,11 +261,9 @@ test('can write strings as objects', function(t) {
process.nextTick(cb);
};
w.on('finish', function() {
w.on('finish', common.mustCall(function() {
assert.deepStrictEqual(list, ['0', '1', '2', '3', '4']);
t.end();
});
}));
w.write('0');
w.write('1');
@ -320,9 +271,10 @@ test('can write strings as objects', function(t) {
w.write('3');
w.write('4');
w.end();
});
}
test('buffers finish until cb is called', function(t) {
{
// Verify that stream buffers finish until callback is called
const w = new Writable({
objectMode: true
});
@ -337,12 +289,10 @@ test('buffers finish until cb is called', function(t) {
});
};
w.on('finish', function() {
w.on('finish', common.mustCall(function() {
assert.strictEqual(called, true);
t.end();
});
}));
w.write('foo');
w.end();
});
}

69
test/parallel/test-stream2-readable-from-list.js

@ -26,33 +26,6 @@ const assert = require('assert');
const fromList = require('_stream_readable')._fromList;
const BufferList = require('internal/streams/BufferList');
// tiny node-tap lookalike.
const tests = [];
let count = 0;
function test(name, fn) {
count++;
tests.push([name, fn]);
}
function run() {
const next = tests.shift();
if (!next)
return console.error('ok');
const name = next[0];
const fn = next[1];
console.log('# %s', name);
fn({
same: assert.deepStrictEqual,
equal: assert.strictEqual,
end: function() {
count--;
run();
}
});
}
function bufferListFromArray(arr) {
const bl = new BufferList();
for (let i = 0; i < arr.length; ++i)
@ -60,15 +33,8 @@ function bufferListFromArray(arr) {
return bl;
}
// ensure all tests have run
process.on('exit', function() {
assert.strictEqual(count, 0);
});
process.nextTick(run);
test('buffers', function(t) {
{
// Verify behavior with buffers
let list = [ Buffer.from('foog'),
Buffer.from('bark'),
Buffer.from('bazy'),
@ -77,27 +43,26 @@ test('buffers', function(t) {
// read more than the first element.
let ret = fromList(6, { buffer: list, length: 16 });
t.equal(ret.toString(), 'foogba');
assert.strictEqual(ret.toString(), 'foogba');
// read exactly the first element.
ret = fromList(2, { buffer: list, length: 10 });
t.equal(ret.toString(), 'rk');
assert.strictEqual(ret.toString(), 'rk');
// read less than the first element.
ret = fromList(2, { buffer: list, length: 8 });
t.equal(ret.toString(), 'ba');
assert.strictEqual(ret.toString(), 'ba');
// read more than we have.
ret = fromList(100, { buffer: list, length: 6 });
t.equal(ret.toString(), 'zykuel');
assert.strictEqual(ret.toString(), 'zykuel');
// all consumed.
t.same(list, new BufferList());
t.end();
});
assert.deepStrictEqual(list, new BufferList());
}
test('strings', function(t) {
{
// Verify behavior with strings
let list = [ 'foog',
'bark',
'bazy',
@ -106,22 +71,20 @@ test('strings', function(t) {
// read more than the first element.
let ret = fromList(6, { buffer: list, length: 16, decoder: true });
t.equal(ret, 'foogba');
assert.strictEqual(ret, 'foogba');
// read exactly the first element.
ret = fromList(2, { buffer: list, length: 10, decoder: true });
t.equal(ret, 'rk');
assert.strictEqual(ret, 'rk');
// read less than the first element.
ret = fromList(2, { buffer: list, length: 8, decoder: true });
t.equal(ret, 'ba');
assert.strictEqual(ret, 'ba');
// read more than we have.
ret = fromList(100, { buffer: list, length: 6, decoder: true });
t.equal(ret, 'zykuel');
assert.strictEqual(ret, 'zykuel');
// all consumed.
t.same(list, new BufferList());
t.end();
});
assert.deepStrictEqual(list, new BufferList());
}

146
test/parallel/test-stream2-set-encoding.js

@ -20,47 +20,11 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const R = require('_stream_readable');
const util = require('util');
// tiny node-tap lookalike.
const tests = [];
let count = 0;
function test(name, fn) {
count++;
tests.push([name, fn]);
}
function run() {
const next = tests.shift();
if (!next)
return console.error('ok');
const name = next[0];
const fn = next[1];
console.log('# %s', name);
fn({
same: assert.deepStrictEqual,
equal: assert.strictEqual,
end: function() {
count--;
run();
}
});
}
// ensure all tests have run
process.on('exit', function() {
assert.strictEqual(count, 0);
});
process.nextTick(run);
/////
util.inherits(TestReader, R);
function TestReader(n, opts) {
@ -89,13 +53,12 @@ TestReader.prototype._read = function(n) {
this.pos += n;
const ret = Buffer.alloc(n, 'a');
console.log('this.push(ret)', ret);
return this.push(ret);
}.bind(this), 1);
};
test('setEncoding utf8', function(t) {
{
// Verify utf8 encoding
const tr = new TestReader(100);
tr.setEncoding('utf8');
const out = [];
@ -117,14 +80,14 @@ test('setEncoding utf8', function(t) {
out.push(chunk);
});
tr.on('end', function() {
t.same(out, expect);
t.end();
});
});
tr.on('end', common.mustCall(function() {
assert.deepStrictEqual(out, expect);
}));
}
test('setEncoding hex', function(t) {
{
// Verify hex encoding
const tr = new TestReader(100);
tr.setEncoding('hex');
const out = [];
@ -156,13 +119,13 @@ test('setEncoding hex', function(t) {
out.push(chunk);
});
tr.on('end', function() {
t.same(out, expect);
t.end();
});
});
tr.on('end', common.mustCall(function() {
assert.deepStrictEqual(out, expect);
}));
}
test('setEncoding hex with read(13)', function(t) {
{
// Verify hex encoding with read(13)
const tr = new TestReader(100);
tr.setEncoding('hex');
const out = [];
@ -185,20 +148,18 @@ test('setEncoding hex with read(13)', function(t) {
'16161' ];
tr.on('readable', function flow() {
console.log('readable once');
let chunk;
while (null !== (chunk = tr.read(13)))
out.push(chunk);
});
tr.on('end', function() {
console.log('END');
t.same(out, expect);
t.end();
});
});
tr.on('end', common.mustCall(function() {
assert.deepStrictEqual(out, expect);
}));
}
test('setEncoding base64', function(t) {
{
// Verify base64 encoding
const tr = new TestReader(100);
tr.setEncoding('base64');
const out = [];
@ -224,13 +185,13 @@ test('setEncoding base64', function(t) {
out.push(chunk);
});
tr.on('end', function() {
t.same(out, expect);
t.end();
});
});
tr.on('end', common.mustCall(function() {
assert.deepStrictEqual(out, expect);
}));
}
test('encoding: utf8', function(t) {
{
// Verify utf8 encoding
const tr = new TestReader(100, { encoding: 'utf8' });
const out = [];
const expect =
@ -251,14 +212,14 @@ test('encoding: utf8', function(t) {
out.push(chunk);
});
tr.on('end', function() {
t.same(out, expect);
t.end();
});
});
tr.on('end', common.mustCall(function() {
assert.deepStrictEqual(out, expect);
}));
}
test('encoding: hex', function(t) {
{
// Verify hex encoding
const tr = new TestReader(100, { encoding: 'hex' });
const out = [];
const expect =
@ -289,13 +250,13 @@ test('encoding: hex', function(t) {
out.push(chunk);
});
tr.on('end', function() {
t.same(out, expect);
t.end();
});
});
tr.on('end', common.mustCall(function() {
assert.deepStrictEqual(out, expect);
}));
}
test('encoding: hex with read(13)', function(t) {
{
// Verify hex encoding with read(13)
const tr = new TestReader(100, { encoding: 'hex' });
const out = [];
const expect =
@ -322,13 +283,13 @@ test('encoding: hex with read(13)', function(t) {
out.push(chunk);
});
tr.on('end', function() {
t.same(out, expect);
t.end();
});
});
tr.on('end', common.mustCall(function() {
assert.deepStrictEqual(out, expect);
}));
}
test('encoding: base64', function(t) {
{
// Verify base64 encoding
const tr = new TestReader(100, { encoding: 'base64' });
const out = [];
const expect =
@ -353,14 +314,13 @@ test('encoding: base64', function(t) {
out.push(chunk);
});
tr.on('end', function() {
t.same(out, expect);
t.end();
});
});
tr.on('end', common.mustCall(function() {
assert.deepStrictEqual(out, expect);
}));
}
test('chainable', function(t) {
{
// Verify chaining behavior
const tr = new TestReader(100);
t.equal(tr.setEncoding('utf8'), tr);
t.end();
});
assert.deepStrictEqual(tr.setEncoding('utf8'), tr);
}

338
test/parallel/test-stream2-transform.js

@ -20,49 +20,13 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const PassThrough = require('_stream_passthrough');
const Transform = require('_stream_transform');
// tiny node-tap lookalike.
const tests = [];
let count = 0;
function test(name, fn) {
count++;
tests.push([name, fn]);
}
function run() {
const next = tests.shift();
if (!next)
return console.error('ok');
const name = next[0];
const fn = next[1];
console.log('# %s', name);
fn({
same: assert.deepStrictEqual,
equal: assert.strictEqual,
ok: assert,
end: function() {
count--;
run();
}
});
}
// ensure all tests have run
process.on('exit', function() {
assert.strictEqual(count, 0);
});
process.nextTick(run);
/////
test('writable side consumption', function(t) {
{
// Verify writable side consumption
const tx = new Transform({
highWaterMark: 10
});
@ -79,17 +43,16 @@ test('writable side consumption', function(t) {
}
tx.end();
t.equal(tx._readableState.length, 10);
t.equal(transformed, 10);
t.equal(tx._transformState.writechunk.length, 5);
t.same(tx._writableState.getBuffer().map(function(c) {
assert.strictEqual(tx._readableState.length, 10);
assert.strictEqual(transformed, 10);
assert.strictEqual(tx._transformState.writechunk.length, 5);
assert.deepStrictEqual(tx._writableState.getBuffer().map(function(c) {
return c.chunk.length;
}), [6, 7, 8, 9, 10]);
}
t.end();
});
test('passthrough', function(t) {
{
// Verify passthrough behavior
const pt = new PassThrough();
pt.write(Buffer.from('foog'));
@ -98,14 +61,14 @@ test('passthrough', function(t) {
pt.write(Buffer.from('kuel'));
pt.end();
t.equal(pt.read(5).toString(), 'foogb');
t.equal(pt.read(5).toString(), 'arkba');
t.equal(pt.read(5).toString(), 'zykue');
t.equal(pt.read(5).toString(), 'l');
t.end();
});
assert.strictEqual(pt.read(5).toString(), 'foogb');
assert.strictEqual(pt.read(5).toString(), 'arkba');
assert.strictEqual(pt.read(5).toString(), 'zykue');
assert.strictEqual(pt.read(5).toString(), 'l');
}
test('object passthrough', function(t) {
{
// Verify object passthrough behavior
const pt = new PassThrough({ objectMode: true });
pt.write(1);
@ -117,25 +80,24 @@ test('object passthrough', function(t) {
pt.write({ a: 'b'});
pt.end();
t.equal(pt.read(), 1);
t.equal(pt.read(), true);
t.equal(pt.read(), false);
t.equal(pt.read(), 0);
t.equal(pt.read(), 'foo');
t.equal(pt.read(), '');
t.same(pt.read(), { a: 'b'});
t.end();
});
test('passthrough constructor', function(t) {
assert.strictEqual(pt.read(), 1);
assert.strictEqual(pt.read(), true);
assert.strictEqual(pt.read(), false);
assert.strictEqual(pt.read(), 0);
assert.strictEqual(pt.read(), 'foo');
assert.strictEqual(pt.read(), '');
assert.deepStrictEqual(pt.read(), { a: 'b'});
}
{
// Verify passthrough constructor behavior
const pt = PassThrough();
assert(pt instanceof PassThrough);
}
t.end();
});
test('simple transform', function(t) {
{
// Perform a simple transform
const pt = new Transform();
pt._transform = function(c, e, cb) {
const ret = Buffer.alloc(c.length, 'x');
@ -149,14 +111,14 @@ test('simple transform', function(t) {
pt.write(Buffer.from('kuel'));
pt.end();
t.equal(pt.read(5).toString(), 'xxxxx');
t.equal(pt.read(5).toString(), 'xxxxx');
t.equal(pt.read(5).toString(), 'xxxxx');
t.equal(pt.read(5).toString(), 'x');
t.end();
});
assert.strictEqual(pt.read(5).toString(), 'xxxxx');
assert.strictEqual(pt.read(5).toString(), 'xxxxx');
assert.strictEqual(pt.read(5).toString(), 'xxxxx');
assert.strictEqual(pt.read(5).toString(), 'x');
}
test('simple object transform', function(t) {
{
// Verify simple object transform
const pt = new Transform({ objectMode: true });
pt._transform = function(c, e, cb) {
pt.push(JSON.stringify(c));
@ -172,17 +134,17 @@ test('simple object transform', function(t) {
pt.write({ a: 'b'});
pt.end();
t.equal(pt.read(), '1');
t.equal(pt.read(), 'true');
t.equal(pt.read(), 'false');
t.equal(pt.read(), '0');
t.equal(pt.read(), '"foo"');
t.equal(pt.read(), '""');
t.equal(pt.read(), '{"a":"b"}');
t.end();
});
test('async passthrough', function(t) {
assert.strictEqual(pt.read(), '1');
assert.strictEqual(pt.read(), 'true');
assert.strictEqual(pt.read(), 'false');
assert.strictEqual(pt.read(), '0');
assert.strictEqual(pt.read(), '"foo"');
assert.strictEqual(pt.read(), '""');
assert.strictEqual(pt.read(), '{"a":"b"}');
}
{
// Verify async passthrough
const pt = new Transform();
pt._transform = function(chunk, encoding, cb) {
setTimeout(function() {
@ -197,16 +159,16 @@ test('async passthrough', function(t) {
pt.write(Buffer.from('kuel'));
pt.end();
pt.on('finish', function() {
t.equal(pt.read(5).toString(), 'foogb');
t.equal(pt.read(5).toString(), 'arkba');
t.equal(pt.read(5).toString(), 'zykue');
t.equal(pt.read(5).toString(), 'l');
t.end();
});
});
pt.on('finish', common.mustCall(function() {
assert.strictEqual(pt.read(5).toString(), 'foogb');
assert.strictEqual(pt.read(5).toString(), 'arkba');
assert.strictEqual(pt.read(5).toString(), 'zykue');
assert.strictEqual(pt.read(5).toString(), 'l');
}));
}
test('assymetric transform (expand)', function(t) {
{
// Verify assymetric transform (expand)
const pt = new Transform();
// emit each chunk 2 times.
@ -226,19 +188,19 @@ test('assymetric transform (expand)', function(t) {
pt.write(Buffer.from('kuel'));
pt.end();
pt.on('finish', function() {
t.equal(pt.read(5).toString(), 'foogf');
t.equal(pt.read(5).toString(), 'oogba');
t.equal(pt.read(5).toString(), 'rkbar');
t.equal(pt.read(5).toString(), 'kbazy');
t.equal(pt.read(5).toString(), 'bazyk');
t.equal(pt.read(5).toString(), 'uelku');
t.equal(pt.read(5).toString(), 'el');
t.end();
});
});
pt.on('finish', common.mustCall(function() {
assert.strictEqual(pt.read(5).toString(), 'foogf');
assert.strictEqual(pt.read(5).toString(), 'oogba');
assert.strictEqual(pt.read(5).toString(), 'rkbar');
assert.strictEqual(pt.read(5).toString(), 'kbazy');
assert.strictEqual(pt.read(5).toString(), 'bazyk');
assert.strictEqual(pt.read(5).toString(), 'uelku');
assert.strictEqual(pt.read(5).toString(), 'el');
}));
}
test('assymetric transform (compress)', function(t) {
{
// Verify assymetric trasform (compress)
const pt = new Transform();
// each output is the first char of 3 consecutive chunks,
@ -283,17 +245,17 @@ test('assymetric transform (compress)', function(t) {
pt.end();
// 'abcdeabcdeabcd'
pt.on('finish', function() {
t.equal(pt.read(5).toString(), 'abcde');
t.equal(pt.read(5).toString(), 'abcde');
t.equal(pt.read(5).toString(), 'abcd');
t.end();
});
});
pt.on('finish', common.mustCall(function() {
assert.strictEqual(pt.read(5).toString(), 'abcde');
assert.strictEqual(pt.read(5).toString(), 'abcde');
assert.strictEqual(pt.read(5).toString(), 'abcd');
}));
}
// this tests for a stall when data is written to a full stream
// that has empty transforms.
test('complex transform', function(t) {
{
// Verify compex transform behavior
let count = 0;
let saved = null;
const pt = new Transform({highWaterMark: 3});
@ -314,118 +276,96 @@ test('complex transform', function(t) {
pt.once('readable', function() {
process.nextTick(function() {
pt.write(Buffer.from('d'));
pt.write(Buffer.from('ef'), function() {
pt.write(Buffer.from('ef'), common.mustCall(function() {
pt.end();
t.end();
});
t.equal(pt.read().toString(), 'abcdef');
t.equal(pt.read(), null);
}));
assert.strictEqual(pt.read().toString(), 'abcdef');
assert.strictEqual(pt.read(), null);
});
});
pt.write(Buffer.from('abc'));
});
}
test('passthrough event emission', function(t) {
{
// Verify passthrough event emission
const pt = new PassThrough();
let emits = 0;
pt.on('readable', function() {
console.error('>>> emit readable %d', emits);
emits++;
});
pt.write(Buffer.from('foog'));
console.error('need emit 0');
pt.write(Buffer.from('bark'));
console.error('should have emitted readable now 1 === %d', emits);
t.equal(emits, 1);
t.equal(pt.read(5).toString(), 'foogb');
t.equal(String(pt.read(5)), 'null');
console.error('need emit 1');
assert.strictEqual(emits, 1);
assert.strictEqual(pt.read(5).toString(), 'foogb');
assert.strictEqual(String(pt.read(5)), 'null');
pt.write(Buffer.from('bazy'));
console.error('should have emitted, but not again');
pt.write(Buffer.from('kuel'));
console.error('should have emitted readable now 2 === %d', emits);
t.equal(emits, 2);
t.equal(pt.read(5).toString(), 'arkba');
t.equal(pt.read(5).toString(), 'zykue');
t.equal(pt.read(5), null);
console.error('need emit 2');
assert.strictEqual(emits, 2);
assert.strictEqual(pt.read(5).toString(), 'arkba');
assert.strictEqual(pt.read(5).toString(), 'zykue');
assert.strictEqual(pt.read(5), null);
pt.end();
t.equal(emits, 3);
assert.strictEqual(emits, 3);
assert.strictEqual(pt.read(5).toString(), 'l');
assert.strictEqual(pt.read(5), null);
t.equal(pt.read(5).toString(), 'l');
t.equal(pt.read(5), null);
console.error('should not have emitted again');
t.equal(emits, 3);
t.end();
});
assert.strictEqual(emits, 3);
}
test('passthrough event emission reordered', function(t) {
{
// Verify passthrough event emission reordering
const pt = new PassThrough();
let emits = 0;
pt.on('readable', function() {
console.error('emit readable', emits);
emits++;
});
pt.write(Buffer.from('foog'));
console.error('need emit 0');
pt.write(Buffer.from('bark'));
console.error('should have emitted readable now 1 === %d', emits);
t.equal(emits, 1);
t.equal(pt.read(5).toString(), 'foogb');
t.equal(pt.read(5), null);
console.error('need emit 1');
pt.once('readable', function() {
t.equal(pt.read(5).toString(), 'arkba');
t.equal(pt.read(5), null);
console.error('need emit 2');
pt.once('readable', function() {
t.equal(pt.read(5).toString(), 'zykue');
t.equal(pt.read(5), null);
pt.once('readable', function() {
t.equal(pt.read(5).toString(), 'l');
t.equal(pt.read(5), null);
t.equal(emits, 4);
t.end();
});
assert.strictEqual(emits, 1);
assert.strictEqual(pt.read(5).toString(), 'foogb');
assert.strictEqual(pt.read(5), null);
pt.once('readable', common.mustCall(function() {
assert.strictEqual(pt.read(5).toString(), 'arkba');
assert.strictEqual(pt.read(5), null);
pt.once('readable', common.mustCall(function() {
assert.strictEqual(pt.read(5).toString(), 'zykue');
assert.strictEqual(pt.read(5), null);
pt.once('readable', common.mustCall(function() {
assert.strictEqual(pt.read(5).toString(), 'l');
assert.strictEqual(pt.read(5), null);
assert.strictEqual(emits, 4);
}));
pt.end();
});
}));
pt.write(Buffer.from('kuel'));
});
}));
pt.write(Buffer.from('bazy'));
});
}
test('passthrough facaded', function(t) {
console.error('passthrough facaded');
{
// Verify passthrough facade
const pt = new PassThrough();
const datas = [];
pt.on('data', function(chunk) {
datas.push(chunk.toString());
});
pt.on('end', function() {
t.same(datas, ['foog', 'bark', 'bazy', 'kuel']);
t.end();
});
pt.on('end', common.mustCall(function() {
assert.deepStrictEqual(datas, ['foog', 'bark', 'bazy', 'kuel']);
}));
pt.write(Buffer.from('foog'));
setTimeout(function() {
@ -440,10 +380,10 @@ test('passthrough facaded', function(t) {
}, 10);
}, 10);
}, 10);
});
}
test('object transform (json parse)', function(t) {
console.error('json parse stream');
{
// Verify object transform (JSON parse)
const jp = new Transform({ objectMode: true });
jp._transform = function(data, encoding, cb) {
try {
@ -471,21 +411,20 @@ test('object transform (json parse)', function(t) {
objects.forEach(function(obj) {
jp.write(JSON.stringify(obj));
const res = jp.read();
t.same(res, obj);
assert.deepStrictEqual(res, obj);
});
jp.end();
// read one more time to get the 'end' event
jp.read();
process.nextTick(function() {
t.ok(ended);
t.end();
});
});
process.nextTick(common.mustCall(function() {
assert.strictEqual(ended, true);
}));
}
test('object transform (json stringify)', function(t) {
console.error('json parse stream');
{
// Verify object transform (JSON stringify)
const js = new Transform({ objectMode: true });
js._transform = function(data, encoding, cb) {
try {
@ -513,15 +452,14 @@ test('object transform (json stringify)', function(t) {
objects.forEach(function(obj) {
js.write(obj);
const res = js.read();
t.equal(res, JSON.stringify(obj));
assert.strictEqual(res, JSON.stringify(obj));
});
js.end();
// read one more time to get the 'end' event
js.read();
process.nextTick(function() {
t.ok(ended);
t.end();
});
});
process.nextTick(common.mustCall(function() {
assert.strictEqual(ended, true);
}));
}

260
test/parallel/test-stream2-writable.js

@ -49,66 +49,32 @@ for (let i = 0; i < chunks.length; i++) {
chunks[i] = 'x'.repeat(i);
}
// tiny node-tap lookalike.
const tests = [];
let count = 0;
function test(name, fn) {
count++;
tests.push([name, fn]);
}
function run() {
const next = tests.shift();
if (!next)
return console.error('ok');
const name = next[0];
const fn = next[1];
console.log('# %s', name);
fn({
same: assert.deepStrictEqual,
equal: assert.strictEqual,
end: function() {
count--;
run();
}
});
}
// ensure all tests have run
process.on('exit', function() {
assert.strictEqual(count, 0);
});
process.nextTick(run);
test('write fast', function(t) {
{
// Verify fast writing
const tw = new TestWriter({
highWaterMark: 100
});
tw.on('finish', function() {
t.same(tw.buffer, chunks, 'got chunks in the right order');
t.end();
});
tw.on('finish', common.mustCall(function() {
assert.deepStrictEqual(tw.buffer, chunks, 'got chunks in the right order');
}));
chunks.forEach(function(chunk) {
// screw backpressure. Just buffer it all up.
// Ignore backpressure. Just buffer it all up.
tw.write(chunk);
});
tw.end();
});
}
test('write slow', function(t) {
{
// Verify slow writing
const tw = new TestWriter({
highWaterMark: 100
});
tw.on('finish', function() {
t.same(tw.buffer, chunks, 'got chunks in the right order');
t.end();
});
tw.on('finish', common.mustCall(function() {
assert.deepStrictEqual(tw.buffer, chunks, 'got chunks in the right order');
}));
let i = 0;
(function W() {
@ -118,20 +84,20 @@ test('write slow', function(t) {
else
tw.end();
})();
});
}
test('write backpressure', function(t) {
{
// Verify write backpressure
const tw = new TestWriter({
highWaterMark: 50
});
let drains = 0;
tw.on('finish', function() {
t.same(tw.buffer, chunks, 'got chunks in the right order');
t.equal(drains, 17);
t.end();
});
tw.on('finish', common.mustCall(function() {
assert.deepStrictEqual(tw.buffer, chunks, 'got chunks in the right order');
assert.strictEqual(drains, 17);
}));
tw.on('drain', function() {
drains++;
@ -151,9 +117,10 @@ test('write backpressure', function(t) {
tw.end();
}
})();
});
}
test('write bufferize', function(t) {
{
// Verify write buffersize
const tw = new TestWriter({
highWaterMark: 100
});
@ -173,7 +140,7 @@ test('write bufferize', function(t) {
undefined ];
tw.on('finish', function() {
t.same(tw.buffer, chunks, 'got the expected chunks');
assert.deepStrictEqual(tw.buffer, chunks, 'got the expected chunks');
});
chunks.forEach(function(chunk, i) {
@ -181,10 +148,10 @@ test('write bufferize', function(t) {
chunk = Buffer.from(chunk);
tw.write(chunk.toString(enc), enc);
});
t.end();
});
}
test('write no bufferize', function(t) {
{
// Verify write with no buffersize
const tw = new TestWriter({
highWaterMark: 100,
decodeStrings: false
@ -211,7 +178,7 @@ test('write no bufferize', function(t) {
undefined ];
tw.on('finish', function() {
t.same(tw.buffer, chunks, 'got the expected chunks');
assert.deepStrictEqual(tw.buffer, chunks, 'got the expected chunks');
});
chunks.forEach(function(chunk, i) {
@ -219,10 +186,10 @@ test('write no bufferize', function(t) {
chunk = Buffer.from(chunk);
tw.write(chunk.toString(enc), enc);
});
t.end();
});
}
test('write callbacks', function(t) {
{
// Verify write callbacks
const callbacks = chunks.map(function(chunk, i) {
return [i, function() {
callbacks._called[i] = chunk;
@ -237,118 +204,115 @@ test('write callbacks', function(t) {
highWaterMark: 100
});
tw.on('finish', function() {
process.nextTick(function() {
t.same(tw.buffer, chunks, 'got chunks in the right order');
t.same(callbacks._called, chunks, 'called all callbacks');
t.end();
});
});
tw.on('finish', common.mustCall(function() {
process.nextTick(common.mustCall(function() {
assert.deepStrictEqual(tw.buffer, chunks,
'got chunks in the right order');
assert.deepStrictEqual(callbacks._called, chunks, 'called all callbacks');
}));
}));
chunks.forEach(function(chunk, i) {
tw.write(chunk, callbacks[`callback-${i}`]);
});
tw.end();
});
}
test('end callback', function(t) {
{
// Verify end() callback
const tw = new TestWriter();
tw.end(function() {
t.end();
});
});
tw.end(common.mustCall());
}
test('end callback with chunk', function(t) {
{
// Verify end() callback with chunk
const tw = new TestWriter();
tw.end(Buffer.from('hello world'), function() {
t.end();
});
});
tw.end(Buffer.from('hello world'), common.mustCall());
}
test('end callback with chunk and encoding', function(t) {
{
// Verify end() callback with chunk and encoding
const tw = new TestWriter();
tw.end('hello world', 'ascii', function() {
t.end();
});
});
tw.end('hello world', 'ascii', common.mustCall());
}
test('end callback after .write() call', function(t) {
{
// Verify end() callback after write() call
const tw = new TestWriter();
tw.write(Buffer.from('hello world'));
tw.end(function() {
t.end();
});
});
tw.end(common.mustCall());
}
test('end callback called after write callback', function(t) {
{
// Verify end() callback after write() callback
const tw = new TestWriter();
let writeCalledback = false;
tw.write(Buffer.from('hello world'), function() {
writeCalledback = true;
});
tw.end(function() {
t.equal(writeCalledback, true);
t.end();
});
});
tw.end(common.mustCall(function() {
assert.strictEqual(writeCalledback, true);
}));
}
test('encoding should be ignored for buffers', function(t) {
{
// Verify encoding is ignored for buffers
const tw = new W();
const hex = '018b5e9a8f6236ffe30e31baf80d2cf6eb';
tw._write = function(chunk) {
t.equal(chunk.toString('hex'), hex);
t.end();
};
tw._write = common.mustCall(function(chunk) {
assert.strictEqual(chunk.toString('hex'), hex);
});
const buf = Buffer.from(hex, 'hex');
tw.write(buf, 'latin1');
});
}
test('writables are not pipable', function(t) {
{
// Verify writables cannot be piped
const w = new W();
w._write = common.noop;
w._write = common.mustNotCall();
let gotError = false;
w.on('error', function() {
gotError = true;
});
w.pipe(process.stdout);
assert(gotError);
t.end();
});
assert.strictEqual(gotError, true);
}
test('duplexes are pipable', function(t) {
{
// Verify that duplex streams cannot be piped
const d = new D();
d._read = common.noop;
d._write = common.noop;
d._read = common.mustCall();
d._write = common.mustNotCall();
let gotError = false;
d.on('error', function() {
gotError = true;
});
d.pipe(process.stdout);
assert(!gotError);
t.end();
});
assert.strictEqual(gotError, false);
}
test('end(chunk) two times is an error', function(t) {
{
// Verify that end(chunk) twice is an error
const w = new W();
w._write = common.noop;
let gotError = false;
w.on('error', function(er) {
gotError = true;
t.equal(er.message, 'write after end');
assert.strictEqual(er.message, 'write after end');
});
w.end('this is the end');
w.end('and so is this');
process.nextTick(function() {
assert(gotError);
t.end();
});
});
process.nextTick(common.mustCall(function() {
assert.strictEqual(gotError, true);
}));
}
test('dont end while writing', function(t) {
{
// Verify stream doesn't end while writing
const w = new W();
let wrote = false;
w._write = function(chunk, e, cb) {
assert(!this.writing);
assert.strictEqual(this.writing, undefined);
wrote = true;
this.writing = true;
setTimeout(function() {
@ -356,15 +320,15 @@ test('dont end while writing', function(t) {
cb();
}, 1);
};
w.on('finish', function() {
assert(wrote);
t.end();
});
w.on('finish', common.mustCall(function() {
assert.strictEqual(wrote, true);
}));
w.write(Buffer.alloc(0));
w.end();
});
}
test('finish does not come before write cb', function(t) {
{
// Verify finish does not come before write() callback
const w = new W();
let writeCb = false;
w._write = function(chunk, e, cb) {
@ -373,43 +337,42 @@ test('finish does not come before write cb', function(t) {
cb();
}, 10);
};
w.on('finish', function() {
assert(writeCb);
t.end();
});
w.on('finish', common.mustCall(function() {
assert.strictEqual(writeCb, true);
}));
w.write(Buffer.alloc(0));
w.end();
});
}
test('finish does not come before sync _write cb', function(t) {
{
// Verify finish does not come before synchronous _write() callback
const w = new W();
let writeCb = false;
w._write = function(chunk, e, cb) {
cb();
};
w.on('finish', function() {
assert(writeCb);
t.end();
});
w.on('finish', common.mustCall(function() {
assert.strictEqual(writeCb, true);
}));
w.write(Buffer.alloc(0), function() {
writeCb = true;
});
w.end();
});
}
test('finish is emitted if last chunk is empty', function(t) {
{
// Verify finish is emitted if the last chunk is empty
const w = new W();
w._write = function(chunk, e, cb) {
process.nextTick(cb);
};
w.on('finish', function() {
t.end();
});
w.on('finish', common.mustCall());
w.write(Buffer.allocUnsafe(1));
w.end(Buffer.alloc(0));
});
}
test('finish is emitted after shutdown', function(t) {
{
// Verify that finish is emitted after shutdown
const w = new W();
let shutdown = false;
@ -424,9 +387,8 @@ test('finish is emitted after shutdown', function(t) {
process.nextTick(cb);
};
w.on('finish', common.mustCall(function() {
assert(shutdown);
t.end();
assert.strictEqual(shutdown, true);
}));
w.write(Buffer.allocUnsafe(1));
w.end(Buffer.allocUnsafe(0));
});
}

Loading…
Cancel
Save