From 47b1c3b43ca92ed1808c17fdfed185060dd1bd63 Mon Sep 17 00:00:00 2001 From: Ashish Kaila Date: Sat, 21 Oct 2017 00:27:24 -0700 Subject: [PATCH] test: add test for WrapStream readStop PR-URL: https://github.com/nodejs/node/pull/16356 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Anatoli Papirovski Reviewed-By: Gibson Fahnestock --- .../parallel/test-wrap-js-stream-read-stop.js | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/parallel/test-wrap-js-stream-read-stop.js diff --git a/test/parallel/test-wrap-js-stream-read-stop.js b/test/parallel/test-wrap-js-stream-read-stop.js new file mode 100644 index 00000000000000..f51b3ecf524e30 --- /dev/null +++ b/test/parallel/test-wrap-js-stream-read-stop.js @@ -0,0 +1,42 @@ +// Flags: --expose-internals +'use strict'; + +require('../common'); +const assert = require('assert'); +const WrapStream = require('internal/wrap_js_stream'); +const Stream = require('stream'); + +class FakeStream extends Stream { + constructor() { + super(); + this._paused = false; + } + + pause() { + this._paused = true; + } + + resume() { + this._paused = false; + } + + isPaused() { + return this._paused; + } +} + +const fakeStreamObj = new FakeStream(); +const wrappedStream = new WrapStream(fakeStreamObj); + +// Resume by wrapped stream upon construction +assert.strictEqual(fakeStreamObj.isPaused(), false); + +fakeStreamObj.pause(); + +assert.strictEqual(fakeStreamObj.isPaused(), true); + +fakeStreamObj.resume(); + +assert.strictEqual(wrappedStream.readStop(), 0); + +assert.strictEqual(fakeStreamObj.isPaused(), true);