• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4
5const { Readable } = require('stream');
6const EE = require('events').EventEmitter;
7
8class LegacyStream extends EE {
9  pause() {}
10  resume() {}
11}
12
13{
14  const err = new Error();
15  const oldStream = new LegacyStream();
16  const r = new Readable({ autoDestroy: true })
17    .wrap(oldStream)
18    .on('error', common.mustCall(() => {
19      assert.strictEqual(r._readableState.errorEmitted, true);
20      assert.strictEqual(r._readableState.errored, err);
21      assert.strictEqual(r.destroyed, true);
22    }));
23  oldStream.emit('error', err);
24}
25
26{
27  const err = new Error();
28  const oldStream = new LegacyStream();
29  const r = new Readable({ autoDestroy: false })
30    .wrap(oldStream)
31    .on('error', common.mustCall(() => {
32      assert.strictEqual(r._readableState.errorEmitted, true);
33      assert.strictEqual(r._readableState.errored, err);
34      assert.strictEqual(r.destroyed, false);
35    }));
36  oldStream.emit('error', err);
37}
38