1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const fs = require('fs'); 5 6const tmpdir = require('../common/tmpdir'); 7tmpdir.refresh(); 8 9{ 10 const stream = fs.createReadStream(__filename); 11 stream.on('close', common.mustCall()); 12 test(stream); 13} 14 15{ 16 const stream = fs.createWriteStream(`${tmpdir.path}/dummy`); 17 stream.on('close', common.mustCall()); 18 test(stream); 19} 20 21{ 22 const stream = fs.createReadStream(__filename, { emitClose: true }); 23 stream.on('close', common.mustCall()); 24 test(stream); 25} 26 27{ 28 const stream = fs.createWriteStream(`${tmpdir.path}/dummy2`, 29 { emitClose: true }); 30 stream.on('close', common.mustCall()); 31 test(stream); 32} 33 34 35function test(stream) { 36 const err = new Error('DESTROYED'); 37 stream.on('open', function() { 38 stream.destroy(err); 39 }); 40 stream.on('error', common.mustCall(function(err_) { 41 assert.strictEqual(err_, err); 42 })); 43} 44