MCPcopy Index your code
hub / github.com/nodejs/node / runTest

Function runTest

test/parallel/test-stream2-readable-wrap.js:28–93  ·  view source on GitHub ↗
(highWaterMark, objectMode, produce)

Source from the content-addressed store, hash-verified

26const EE = require('events').EventEmitter;
27
28function runTest(highWaterMark, objectMode, produce) {
29
30 const old = new EE();
31 const r = new Readable({ highWaterMark, objectMode });
32 assert.strictEqual(r, r.wrap(old));
33
34 r.on('end', common.mustCall());
35
36 old.pause = function() {
37 old.emit('pause');
38 flowing = false;
39 };
40
41 old.resume = function() {
42 old.emit('resume');
43 flow();
44 };
45
46 // Make sure pause is only emitted once.
47 let pausing = false;
48 r.on('pause', common.mustCallAtLeast(() => {
49 assert.strictEqual(pausing, false);
50 pausing = true;
51 process.nextTick(() => {
52 pausing = false;
53 });
54 }));
55
56 let flowing;
57 let chunks = 10;
58 let oldEnded = false;
59 const expected = [];
60 function flow() {
61 flowing = true;
62 while (flowing && chunks-- > 0) {
63 const item = produce();
64 expected.push(item);
65 old.emit('data', item);
66 }
67 if (chunks <= 0) {
68 oldEnded = true;
69 old.emit('end');
70 }
71 }
72
73 const w = new Writable({ highWaterMark: highWaterMark * 2,
74 objectMode });
75 const written = [];
76 w._write = function(chunk, encoding, cb) {
77 written.push(chunk);
78 setTimeout(cb, 1);
79 };
80
81 w.on('finish', common.mustCall(function() {
82 performAsserts();
83 }));
84
85 r.pipe(w);

Callers 1

Calls 7

performAssertsFunction · 0.85
flowFunction · 0.70
setTimeoutFunction · 0.50
wrapMethod · 0.45
onMethod · 0.45
emitMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…