Skip to content

Commit

Permalink
test: increase coverage for stream's duplex
Browse files Browse the repository at this point in the history
Make use of Arrow function.
Add a small test and this file's coverage is 100%.
https://github.com/nodejs/node/blob/a647d82f83ad5ddad5db7be2cc24c3d686121792/lib/_stream_duplex.js#L25
Coverage: https://coverage.nodejs.org/coverage-067be658f966dafe/root/_stream_duplex.js.html

PR-URL: #10963
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
hiroppy authored and MylesBorins committed Mar 9, 2017
1 parent dc24127 commit be34b62
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions test/parallel/test-stream-duplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,28 @@ const Duplex = require('stream').Transform;

const stream = new Duplex({ objectMode: true });

assert(Duplex() instanceof Duplex);
assert(stream._readableState.objectMode);
assert(stream._writableState.objectMode);

let written;
let read;

stream._write = function(obj, _, cb) {
stream._write = (obj, _, cb) => {
written = obj;
cb();
};

stream._read = function() {};
stream._read = () => {};

stream.on('data', function(obj) {
stream.on('data', (obj) => {
read = obj;
});

stream.push({ val: 1 });
stream.end({ val: 2 });

process.on('exit', function() {
assert(read.val === 1);
assert(written.val === 2);
process.on('exit', () => {
assert.strictEqual(read.val, 1);
assert.strictEqual(written.val, 2);
});

0 comments on commit be34b62

Please sign in to comment.