• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3require('../common');
4
5const assert = require('assert');
6const stream = require('stream');
7
8const writable = new stream.Writable();
9
10function testStates(ending, finished, ended) {
11  assert.strictEqual(writable._writableState.ending, ending);
12  assert.strictEqual(writable._writableState.finished, finished);
13  assert.strictEqual(writable._writableState.ended, ended);
14}
15
16writable._write = (chunk, encoding, cb) => {
17  // Ending, finished, ended start in false.
18  testStates(false, false, false);
19  cb();
20};
21
22writable.on('finish', () => {
23  // Ending, finished, ended = true.
24  testStates(true, true, true);
25});
26
27const result = writable.end('testing function end()', () => {
28  // Ending, finished, ended = true.
29  testStates(true, true, true);
30});
31
32// End returns the writable instance
33assert.strictEqual(result, writable);
34
35// Ending, ended = true.
36// finished = false.
37testStates(true, false, true);
38