11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_cirequire('../common'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst assert = require('assert'); 61cb0ef41Sopenharmony_ciconst stream = require('stream'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst writable = new stream.Writable(); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cifunction testStates(ending, finished, ended) { 111cb0ef41Sopenharmony_ci assert.strictEqual(writable._writableState.ending, ending); 121cb0ef41Sopenharmony_ci assert.strictEqual(writable._writableState.finished, finished); 131cb0ef41Sopenharmony_ci assert.strictEqual(writable._writableState.ended, ended); 141cb0ef41Sopenharmony_ci} 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciwritable._write = (chunk, encoding, cb) => { 171cb0ef41Sopenharmony_ci // Ending, finished, ended start in false. 181cb0ef41Sopenharmony_ci testStates(false, false, false); 191cb0ef41Sopenharmony_ci cb(); 201cb0ef41Sopenharmony_ci}; 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ciwritable.on('finish', () => { 231cb0ef41Sopenharmony_ci // Ending, finished, ended = true. 241cb0ef41Sopenharmony_ci testStates(true, true, true); 251cb0ef41Sopenharmony_ci}); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ciconst result = writable.end('testing function end()', () => { 281cb0ef41Sopenharmony_ci // Ending, finished, ended = true. 291cb0ef41Sopenharmony_ci testStates(true, true, true); 301cb0ef41Sopenharmony_ci}); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci// End returns the writable instance 331cb0ef41Sopenharmony_ciassert.strictEqual(result, writable); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci// Ending, ended = true. 361cb0ef41Sopenharmony_ci// finished = false. 371cb0ef41Sopenharmony_citestStates(true, false, true); 38