• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const { Duplex } = require('stream');
5const assert = require('assert');
6
7// basic
8{
9  // Find it on Duplex.prototype
10  assert(Duplex.prototype.hasOwnProperty('writableFinished'));
11}
12
13// event
14{
15  const duplex = new Duplex();
16
17  duplex._write = (chunk, encoding, cb) => {
18    // The state finished should start in false.
19    assert.strictEqual(duplex.writableFinished, false);
20    cb();
21  };
22
23  duplex.on('finish', common.mustCall(() => {
24    assert.strictEqual(duplex.writableFinished, true);
25  }));
26
27  duplex.end('testing finished state', common.mustCall(() => {
28    assert.strictEqual(duplex.writableFinished, true);
29  }));
30}
31