11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci// This test ensures that the callback of `OutgoingMessage.prototype.write()` is 61cb0ef41Sopenharmony_ci// called also when writing empty chunks or when the message has no body. 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst assert = require('assert'); 91cb0ef41Sopenharmony_ciconst http = require('http'); 101cb0ef41Sopenharmony_ciconst stream = require('stream'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cifor (const method of ['GET, HEAD']) { 131cb0ef41Sopenharmony_ci const expected = ['a', 'b', '', Buffer.alloc(0), 'c']; 141cb0ef41Sopenharmony_ci const results = []; 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci const writable = new stream.Writable({ 171cb0ef41Sopenharmony_ci write(chunk, encoding, callback) { 181cb0ef41Sopenharmony_ci callback(); 191cb0ef41Sopenharmony_ci } 201cb0ef41Sopenharmony_ci }); 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci const res = new http.ServerResponse({ 231cb0ef41Sopenharmony_ci method: method, 241cb0ef41Sopenharmony_ci httpVersionMajor: 1, 251cb0ef41Sopenharmony_ci httpVersionMinor: 1 261cb0ef41Sopenharmony_ci }); 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci res.assignSocket(writable); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci for (const chunk of expected) { 311cb0ef41Sopenharmony_ci res.write(chunk, () => { 321cb0ef41Sopenharmony_ci results.push(chunk); 331cb0ef41Sopenharmony_ci }); 341cb0ef41Sopenharmony_ci } 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci res.end(common.mustCall(() => { 371cb0ef41Sopenharmony_ci assert.deepStrictEqual(results, expected); 381cb0ef41Sopenharmony_ci })); 391cb0ef41Sopenharmony_ci} 40