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 evanlucas committed Jan 31, 2017
1 parent b5e8413 commit f3efaee
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 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() {
process.on('exit', () => {
assert.strictEqual(read.val, 1);
assert.strictEqual(written.val, 2);
});

0 comments on commit f3efaee

Please sign in to comment.