• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const { Writable } = require('stream');
5const assert = require('assert');
6
7// basic
8{
9  // Find it on Writable.prototype
10  assert(Writable.prototype.hasOwnProperty('writableFinished'));
11}
12
13// event
14{
15  const writable = new Writable();
16
17  writable._write = (chunk, encoding, cb) => {
18    // The state finished should start in false.
19    assert.strictEqual(writable.writableFinished, false);
20    cb();
21  };
22
23  writable.on('finish', common.mustCall(() => {
24    assert.strictEqual(writable.writableFinished, true);
25  }));
26
27  writable.end('testing finished state', common.mustCall(() => {
28    assert.strictEqual(writable.writableFinished, true);
29  }));
30}
31
32{
33  // Emit finish asynchronously
34
35  const w = new Writable({
36    write(chunk, encoding, cb) {
37      cb();
38    }
39  });
40
41  w.end();
42  w.on('finish', common.mustCall());
43}
44