11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst { Transform } = require('stream'); 51cb0ef41Sopenharmony_ciconst assert = require('assert'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci{ 81cb0ef41Sopenharmony_ci const transform = new Transform({ 91cb0ef41Sopenharmony_ci transform(chunk, enc, cb) {} 101cb0ef41Sopenharmony_ci }); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci transform.resume(); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci transform.on('end', common.mustNotCall()); 151cb0ef41Sopenharmony_ci transform.on('close', common.mustCall()); 161cb0ef41Sopenharmony_ci transform.on('finish', common.mustNotCall()); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci transform.destroy(); 191cb0ef41Sopenharmony_ci} 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci{ 221cb0ef41Sopenharmony_ci const transform = new Transform({ 231cb0ef41Sopenharmony_ci transform(chunk, enc, cb) {} 241cb0ef41Sopenharmony_ci }); 251cb0ef41Sopenharmony_ci transform.resume(); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci const expected = new Error('kaboom'); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci transform.on('end', common.mustNotCall()); 301cb0ef41Sopenharmony_ci transform.on('finish', common.mustNotCall()); 311cb0ef41Sopenharmony_ci transform.on('close', common.mustCall()); 321cb0ef41Sopenharmony_ci transform.on('error', common.mustCall((err) => { 331cb0ef41Sopenharmony_ci assert.strictEqual(err, expected); 341cb0ef41Sopenharmony_ci })); 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci transform.destroy(expected); 371cb0ef41Sopenharmony_ci} 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci{ 401cb0ef41Sopenharmony_ci const transform = new Transform({ 411cb0ef41Sopenharmony_ci transform(chunk, enc, cb) {} 421cb0ef41Sopenharmony_ci }); 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci transform._destroy = common.mustCall(function(err, cb) { 451cb0ef41Sopenharmony_ci assert.strictEqual(err, expected); 461cb0ef41Sopenharmony_ci cb(err); 471cb0ef41Sopenharmony_ci }, 1); 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ci const expected = new Error('kaboom'); 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci transform.on('finish', common.mustNotCall('no finish event')); 521cb0ef41Sopenharmony_ci transform.on('close', common.mustCall()); 531cb0ef41Sopenharmony_ci transform.on('error', common.mustCall((err) => { 541cb0ef41Sopenharmony_ci assert.strictEqual(err, expected); 551cb0ef41Sopenharmony_ci })); 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ci transform.destroy(expected); 581cb0ef41Sopenharmony_ci} 591cb0ef41Sopenharmony_ci 601cb0ef41Sopenharmony_ci{ 611cb0ef41Sopenharmony_ci const expected = new Error('kaboom'); 621cb0ef41Sopenharmony_ci const transform = new Transform({ 631cb0ef41Sopenharmony_ci transform(chunk, enc, cb) {}, 641cb0ef41Sopenharmony_ci destroy: common.mustCall(function(err, cb) { 651cb0ef41Sopenharmony_ci assert.strictEqual(err, expected); 661cb0ef41Sopenharmony_ci cb(); 671cb0ef41Sopenharmony_ci }, 1) 681cb0ef41Sopenharmony_ci }); 691cb0ef41Sopenharmony_ci transform.resume(); 701cb0ef41Sopenharmony_ci 711cb0ef41Sopenharmony_ci transform.on('end', common.mustNotCall('no end event')); 721cb0ef41Sopenharmony_ci transform.on('close', common.mustCall()); 731cb0ef41Sopenharmony_ci transform.on('finish', common.mustNotCall('no finish event')); 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ci // Error is swallowed by the custom _destroy 761cb0ef41Sopenharmony_ci transform.on('error', common.mustNotCall('no error event')); 771cb0ef41Sopenharmony_ci 781cb0ef41Sopenharmony_ci transform.destroy(expected); 791cb0ef41Sopenharmony_ci} 801cb0ef41Sopenharmony_ci 811cb0ef41Sopenharmony_ci{ 821cb0ef41Sopenharmony_ci const transform = new Transform({ 831cb0ef41Sopenharmony_ci transform(chunk, enc, cb) {} 841cb0ef41Sopenharmony_ci }); 851cb0ef41Sopenharmony_ci 861cb0ef41Sopenharmony_ci transform._destroy = common.mustCall(function(err, cb) { 871cb0ef41Sopenharmony_ci assert.strictEqual(err, null); 881cb0ef41Sopenharmony_ci cb(); 891cb0ef41Sopenharmony_ci }, 1); 901cb0ef41Sopenharmony_ci 911cb0ef41Sopenharmony_ci transform.destroy(); 921cb0ef41Sopenharmony_ci} 931cb0ef41Sopenharmony_ci 941cb0ef41Sopenharmony_ci{ 951cb0ef41Sopenharmony_ci const transform = new Transform({ 961cb0ef41Sopenharmony_ci transform(chunk, enc, cb) {} 971cb0ef41Sopenharmony_ci }); 981cb0ef41Sopenharmony_ci transform.resume(); 991cb0ef41Sopenharmony_ci 1001cb0ef41Sopenharmony_ci transform._destroy = common.mustCall(function(err, cb) { 1011cb0ef41Sopenharmony_ci assert.strictEqual(err, null); 1021cb0ef41Sopenharmony_ci process.nextTick(() => { 1031cb0ef41Sopenharmony_ci this.push(null); 1041cb0ef41Sopenharmony_ci this.end(); 1051cb0ef41Sopenharmony_ci cb(); 1061cb0ef41Sopenharmony_ci }); 1071cb0ef41Sopenharmony_ci }, 1); 1081cb0ef41Sopenharmony_ci 1091cb0ef41Sopenharmony_ci const fail = common.mustNotCall('no event'); 1101cb0ef41Sopenharmony_ci 1111cb0ef41Sopenharmony_ci transform.on('finish', fail); 1121cb0ef41Sopenharmony_ci transform.on('end', fail); 1131cb0ef41Sopenharmony_ci transform.on('close', common.mustCall()); 1141cb0ef41Sopenharmony_ci 1151cb0ef41Sopenharmony_ci transform.destroy(); 1161cb0ef41Sopenharmony_ci 1171cb0ef41Sopenharmony_ci transform.removeListener('end', fail); 1181cb0ef41Sopenharmony_ci transform.removeListener('finish', fail); 1191cb0ef41Sopenharmony_ci transform.on('end', common.mustCall()); 1201cb0ef41Sopenharmony_ci transform.on('finish', common.mustNotCall()); 1211cb0ef41Sopenharmony_ci} 1221cb0ef41Sopenharmony_ci 1231cb0ef41Sopenharmony_ci{ 1241cb0ef41Sopenharmony_ci const transform = new Transform({ 1251cb0ef41Sopenharmony_ci transform(chunk, enc, cb) {} 1261cb0ef41Sopenharmony_ci }); 1271cb0ef41Sopenharmony_ci 1281cb0ef41Sopenharmony_ci const expected = new Error('kaboom'); 1291cb0ef41Sopenharmony_ci 1301cb0ef41Sopenharmony_ci transform._destroy = common.mustCall(function(err, cb) { 1311cb0ef41Sopenharmony_ci assert.strictEqual(err, null); 1321cb0ef41Sopenharmony_ci cb(expected); 1331cb0ef41Sopenharmony_ci }, 1); 1341cb0ef41Sopenharmony_ci 1351cb0ef41Sopenharmony_ci transform.on('close', common.mustCall()); 1361cb0ef41Sopenharmony_ci transform.on('finish', common.mustNotCall('no finish event')); 1371cb0ef41Sopenharmony_ci transform.on('end', common.mustNotCall('no end event')); 1381cb0ef41Sopenharmony_ci transform.on('error', common.mustCall((err) => { 1391cb0ef41Sopenharmony_ci assert.strictEqual(err, expected); 1401cb0ef41Sopenharmony_ci })); 1411cb0ef41Sopenharmony_ci 1421cb0ef41Sopenharmony_ci transform.destroy(); 1431cb0ef41Sopenharmony_ci} 144