From d6f688ae0d1988f8b86a6cf0d6040a7ce216b5e4 Mon Sep 17 00:00:00 2001 From: "Italo A. Casas" Date: Mon, 26 Sep 2016 22:45:56 -0400 Subject: [PATCH] test: writable stream finished state Add a test for _writableState.finished. PR-URL: https://github.com/nodejs/node/pull/8791 Reviewed-By: Colin Ihrig Reviewed-By: Matteo Collina Related: https://github.com/nodejs/node/issues/8686 --- .../test-stream-writable-finished-state.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/parallel/test-stream-writable-finished-state.js diff --git a/test/parallel/test-stream-writable-finished-state.js b/test/parallel/test-stream-writable-finished-state.js new file mode 100644 index 00000000000000..b42137ed0b5d6b --- /dev/null +++ b/test/parallel/test-stream-writable-finished-state.js @@ -0,0 +1,22 @@ +'use strict'; + +const common = require('../common'); + +const assert = require('assert'); +const stream = require('stream'); + +const writable = new stream.Writable(); + +writable._write = (chunk, encoding, cb) => { + // The state finished should start in false. + assert.strictEqual(writable._writableState.finished, false); + cb(); +}; + +writable.on('finish', common.mustCall(() => { + assert.strictEqual(writable._writableState.finished, true); +})); + +writable.end('testing finished state', common.mustCall(() => { + assert.strictEqual(writable._writableState.finished, true); +}));