• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5const { Readable, Writable } = require('stream');
6
7// This test ensures that if have 'readable' listener
8// on Readable instance it will not disrupt the pipe.
9
10{
11  let receivedData = '';
12  const w = new Writable({
13    write: (chunk, env, callback) => {
14      receivedData += chunk;
15      callback();
16    },
17  });
18
19  const data = ['foo', 'bar', 'baz'];
20  const r = new Readable({
21    read: () => {},
22  });
23
24  r.once('readable', common.mustCall());
25
26  r.pipe(w);
27  r.push(data[0]);
28  r.push(data[1]);
29  r.push(data[2]);
30  r.push(null);
31
32  w.on('finish', common.mustCall(() => {
33    assert.strictEqual(receivedData, data.join(''));
34  }));
35}
36
37{
38  let receivedData = '';
39  const w = new Writable({
40    write: (chunk, env, callback) => {
41      receivedData += chunk;
42      callback();
43    },
44  });
45
46  const data = ['foo', 'bar', 'baz'];
47  const r = new Readable({
48    read: () => {},
49  });
50
51  r.pipe(w);
52  r.push(data[0]);
53  r.push(data[1]);
54  r.push(data[2]);
55  r.push(null);
56  r.once('readable', common.mustCall());
57
58  w.on('finish', common.mustCall(() => {
59    assert.strictEqual(receivedData, data.join(''));
60  }));
61}
62