diff options
author | zero1five <zerodengyin@gmail.com> | 2019-06-02 03:04:56 +0800 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-06-25 14:46:10 -0700 |
commit | 33aef82b42ca689411673784e203e59d3f4eb142 (patch) | |
tree | 2d329d20782e537d53507f5fbe98897803149273 /test/parallel/test-stream-duplex-writable-finished.js | |
parent | 2bb93e11085ea582aea1636f544d900520d479ed (diff) | |
download | node-new-33aef82b42ca689411673784e203e59d3f4eb142.tar.gz |
stream: add writableFinished
add a new getter to duplex stream to replace the property `this
.writableState.finished` of the object that inherited duplex.
Refs: https://github.com/nodejs/node/issues/445
PR-URL: https://github.com/nodejs/node/pull/28007
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'test/parallel/test-stream-duplex-writable-finished.js')
-rw-r--r-- | test/parallel/test-stream-duplex-writable-finished.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/parallel/test-stream-duplex-writable-finished.js b/test/parallel/test-stream-duplex-writable-finished.js new file mode 100644 index 0000000000..6d9e860b61 --- /dev/null +++ b/test/parallel/test-stream-duplex-writable-finished.js @@ -0,0 +1,30 @@ +'use strict'; + +const common = require('../common'); +const { Duplex } = require('stream'); +const assert = require('assert'); + +// basic +{ + // Find it on Duplex.prototype + assert(Duplex.prototype.hasOwnProperty('writableFinished')); +} + +// event +{ + const duplex = new Duplex(); + + duplex._write = (chunk, encoding, cb) => { + // The state finished should start in false. + assert.strictEqual(duplex.writableFinished, false); + cb(); + }; + + duplex.on('finish', common.mustCall(() => { + assert.strictEqual(duplex.writableFinished, true); + })); + + duplex.end('testing finished state', common.mustCall(() => { + assert.strictEqual(duplex.writableFinished, true); + })); +} |