mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 22:31:35 +00:00

Export a new common.noop no-operation function for general use. Allow using common.mustCall() without a fn argument to simplify test cases. Replace various non-op functions throughout tests with common.noop PR-URL: https://github.com/nodejs/node/pull/12027 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
34 lines
933 B
JavaScript
34 lines
933 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
|
|
const { Readable, Writable } = require('stream');
|
|
|
|
const source = Readable({read: common.noop});
|
|
const dest1 = Writable({write: common.noop});
|
|
const dest2 = Writable({write: common.noop});
|
|
|
|
source.pipe(dest1);
|
|
source.pipe(dest2);
|
|
|
|
dest1.on('unpipe', common.mustCall());
|
|
dest2.on('unpipe', common.mustCall());
|
|
|
|
assert.strictEqual(source._readableState.pipes[0], dest1);
|
|
assert.strictEqual(source._readableState.pipes[1], dest2);
|
|
assert.strictEqual(source._readableState.pipes.length, 2);
|
|
|
|
// Should be able to unpipe them in the reverse order that they were piped.
|
|
|
|
source.unpipe(dest2);
|
|
|
|
assert.strictEqual(source._readableState.pipes, dest1);
|
|
assert.notStrictEqual(source._readableState.pipes, dest2);
|
|
|
|
dest2.on('unpipe', common.mustNotCall());
|
|
source.unpipe(dest2);
|
|
|
|
source.unpipe(dest1);
|
|
|
|
assert.strictEqual(source._readableState.pipes, null);
|