summaryrefslogtreecommitdiff
path: root/test/parallel/test-stdout-pipeline-destroy.js
blob: 291579cf69d3d480bde2fc7eb66962a42487a9c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict';

const common = require('../common');
const { Transform, Readable, pipeline } = require('stream');
const assert = require('assert');

const reader = new Readable({
  read(size) { this.push('foo'); }
});

let count = 0;

const err = new Error('this-error-gets-hidden');

const transform = new Transform({
  transform(chunk, enc, cb) {
    if (count++ >= 5)
      this.emit('error', err);
    else
      cb(null, count.toString() + '\n');
  }
});

pipeline(
  reader,
  transform,
  process.stdout,
  common.mustCall((e) => {
    assert.strictEqual(e, err);
  })
);