| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c846184 commit 93ed114
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,65 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + | ||
| 4 | + // Testing Readable Stream resumeScheduled state | ||
| 5 | + | ||
| 6 | + const assert = require('assert'); | ||
| 7 | + const { Readable, Writable } = require('stream'); | ||
| 8 | + | ||
| 9 | + { | ||
| 10 | + // pipe() test case | ||
| 11 | + const r = new Readable({ read() {} }); | ||
| 12 | + const w = new Writable(); | ||
| 13 | + | ||
| 14 | + // resumeScheduled should start = `false`. | ||
| 15 | + assert.strictEqual(r._readableState.resumeScheduled, false); | ||
| 16 | + | ||
| 17 | + // calling pipe() should change the state value = true. | ||
| 18 | + r.pipe(w); | ||
| 19 | + assert.strictEqual(r._readableState.resumeScheduled, true); | ||
| 20 | + | ||
| 21 | + process.nextTick(common.mustCall(() => { | ||
| 22 | + assert.strictEqual(r._readableState.resumeScheduled, false); | ||
| 23 | + })); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + { | ||
| 27 | + // 'data' listener test case | ||
| 28 | + const r = new Readable({ read() {} }); | ||
| 29 | + | ||
| 30 | + // resumeScheduled should start = `false`. | ||
| 31 | + assert.strictEqual(r._readableState.resumeScheduled, false); | ||
| 32 | + | ||
| 33 | + r.push(Buffer.from([1, 2, 3])); | ||
| 34 | + | ||
| 35 | + // adding 'data' listener should change the state value | ||
| 36 | + r.on('data', common.mustCall(() => { | ||
| 37 | + assert.strictEqual(r._readableState.resumeScheduled, false); | ||
| 38 | + })); | ||
| 39 | + assert.strictEqual(r._readableState.resumeScheduled, true); | ||
| 40 | + | ||
| 41 | + process.nextTick(common.mustCall(() => { | ||
| 42 | + assert.strictEqual(r._readableState.resumeScheduled, false); | ||
| 43 | + })); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + { | ||
| 47 | + // resume() test case | ||
| 48 | + const r = new Readable({ read() {} }); | ||
| 49 | + | ||
| 50 | + // resumeScheduled should start = `false`. | ||
| 51 | + assert.strictEqual(r._readableState.resumeScheduled, false); | ||
| 52 | + | ||
| 53 | + // Calling resume() should change the state value. | ||
| 54 | + r.resume(); | ||
| 55 | + assert.strictEqual(r._readableState.resumeScheduled, true); | ||
| 56 | + | ||
| 57 | + r.on('resume', common.mustCall(() => { | ||
| 58 | + // The state value should be `false` again | ||
| 59 | + assert.strictEqual(r._readableState.resumeScheduled, false); | ||
| 60 | + })); | ||
| 61 | + | ||
| 62 | + process.nextTick(common.mustCall(() => { | ||
| 63 | + assert.strictEqual(r._readableState.resumeScheduled, false); | ||
| 64 | + })); | ||
| 65 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments