@@ -83,8 +83,33 @@ const assert = require('assert');
8383 write . on ( 'finish' , common . mustNotCall ( 'no finish event' ) ) ;
8484 write . on ( 'close' , common . mustCall ( ) ) ;
8585
86- // Error is swallowed by the custom _destroy
87- write . on ( 'error' , common . mustNotCall ( 'no error event' ) ) ;
86+ // Error is NOT swallowed by the custom _destroy
87+ write . on ( 'error' , common . mustCall ( ( err ) => {
88+ assert . strictEqual ( err , expected ) ;
89+ } ) ) ;
90+
91+ write . destroy ( expected ) ;
92+ assert . strictEqual ( write . destroyed , true ) ;
93+ }
94+
95+ {
96+ const write = new Writable ( {
97+ write ( chunk , enc , cb ) { cb ( ) ; } ,
98+ destroy : common . mustCall ( function ( err , cb ) {
99+ assert . strictEqual ( err , expected ) ;
100+ cb ( new Error ( 'not this error' ) ) ;
101+ } )
102+ } ) ;
103+
104+ const expected = new Error ( 'kaboom' ) ;
105+
106+ write . on ( 'finish' , common . mustNotCall ( 'no finish event' ) ) ;
107+ write . on ( 'close' , common . mustCall ( ) ) ;
108+
109+ // Error is NOT overriden by the custom _destroy
110+ write . on ( 'error' , common . mustCall ( ( err ) => {
111+ assert . strictEqual ( err , expected ) ;
112+ } ) ) ;
88113
89114 write . destroy ( expected ) ;
90115 assert . strictEqual ( write . destroyed , true ) ;
@@ -167,9 +192,10 @@ const assert = require('assert');
167192 assert . strictEqual ( write . _writableState . errorEmitted , true ) ;
168193 } ) ) ;
169194
170- write . destroy ( new Error ( 'kaboom 1' ) ) ;
195+ const expected = new Error ( 'kaboom 1' ) ;
196+ write . destroy ( expected ) ;
171197 write . destroy ( new Error ( 'kaboom 2' ) ) ;
172- assert . strictEqual ( write . _writableState . errored , true ) ;
198+ assert . strictEqual ( write . _writableState . errored , expected ) ;
173199 assert . strictEqual ( write . _writableState . errorEmitted , false ) ;
174200 assert . strictEqual ( write . destroyed , true ) ;
175201 ticked = true ;
@@ -198,14 +224,15 @@ const assert = require('assert');
198224
199225 writable . destroy ( ) ;
200226 assert . strictEqual ( writable . destroyed , true ) ;
201- assert . strictEqual ( writable . _writableState . errored , false ) ;
227+ assert . strictEqual ( writable . _writableState . errored , null ) ;
202228 assert . strictEqual ( writable . _writableState . errorEmitted , false ) ;
203229
204230 // Test case where `writable.destroy()` is called again with an error before
205231 // the `_destroy()` callback is called.
206- writable . destroy ( new Error ( 'kaboom 2' ) ) ;
232+ const expected = new Error ( 'kaboom 2' ) ;
233+ writable . destroy ( expected ) ;
207234 assert . strictEqual ( writable . _writableState . errorEmitted , false ) ;
208- assert . strictEqual ( writable . _writableState . errored , true ) ;
235+ assert . strictEqual ( writable . _writableState . errored , expected ) ;
209236
210237 ticked = true ;
211238}
@@ -249,6 +276,9 @@ const assert = require('assert');
249276 write . destroy ( expected , common . mustCall ( function ( err ) {
250277 assert . strictEqual ( err , expected ) ;
251278 } ) ) ;
279+ write . on ( 'error' , common . mustCall ( ( err ) => {
280+ assert . strictEqual ( err , expected ) ;
281+ } ) ) ;
252282}
253283
254284{
0 commit comments