@@ -6,7 +6,6 @@ const { Client, errors } = require('..')
66const { createServer } = require ( 'node:http' )
77const { PassThrough, Writable, Readable } = require ( 'node:stream' )
88const EE = require ( 'node:events' )
9- const { guardDisconnect } = require ( './guard-disconnect' )
109
1110test ( 'stream get' , async ( t ) => {
1211 t = tspl ( t , { plan : 9 } )
@@ -23,7 +22,11 @@ test('stream get', async (t) => {
2322 server . listen ( 0 , ( ) => {
2423 const client = new Client ( `http://localhost:${ server . address ( ) . port } ` )
2524 after ( ( ) => client . close ( ) )
26- guardDisconnect ( client , t )
25+ client . on ( 'disconnect' , ( ) => {
26+ if ( ! client . closed && ! client . destroyed ) {
27+ t . fail ( 'unexpected disconnect' )
28+ }
29+ } )
2730
2831 const signal = new EE ( )
2932 client . stream ( {
@@ -67,7 +70,11 @@ test('stream promise get', async (t) => {
6770 server . listen ( 0 , async ( ) => {
6871 const client = new Client ( `http://localhost:${ server . address ( ) . port } ` )
6972 after ( ( ) => client . close ( ) )
70- guardDisconnect ( client , t )
73+ client . on ( 'disconnect' , ( ) => {
74+ if ( ! client . closed && ! client . destroyed ) {
75+ t . fail ( 'unexpected disconnect' )
76+ }
77+ } )
7178
7279 await client . stream ( {
7380 path : '/' ,
@@ -257,7 +264,11 @@ test('stream waits only for writable side', async (t) => {
257264 server . listen ( 0 , ( ) => {
258265 const client = new Client ( `http://localhost:${ server . address ( ) . port } ` )
259266 after ( ( ) => client . close ( ) )
260- guardDisconnect ( client , t )
267+ client . on ( 'disconnect' , ( ) => {
268+ if ( ! client . closed && ! client . destroyed ) {
269+ t . fail ( 'unexpected disconnect' )
270+ }
271+ } )
261272
262273 const pt = new PassThrough ( { autoDestroy : false } )
263274 client . stream ( {
@@ -325,7 +336,11 @@ test('stream destroy if not readable', async (t) => {
325336 server . listen ( 0 , ( ) => {
326337 const client = new Client ( `http://localhost:${ server . address ( ) . port } ` )
327338 after ( client . destroy . bind ( client ) )
328- guardDisconnect ( client , t )
339+ client . on ( 'disconnect' , ( ) => {
340+ if ( ! client . closed && ! client . destroyed ) {
341+ t . fail ( 'unexpected disconnect' )
342+ }
343+ } )
329344
330345 client . stream ( {
331346 path : '/' ,
@@ -402,7 +417,11 @@ test('stream body without destroy', async (t) => {
402417 server . listen ( 0 , ( ) => {
403418 const client = new Client ( `http://localhost:${ server . address ( ) . port } ` )
404419 after ( client . destroy . bind ( client ) )
405- guardDisconnect ( client , t )
420+ client . on ( 'disconnect' , ( ) => {
421+ if ( ! client . closed && ! client . destroyed ) {
422+ t . fail ( 'unexpected disconnect' )
423+ }
424+ } )
406425
407426 client . stream ( {
408427 path : '/' ,
@@ -526,7 +545,11 @@ test('stream abort after complete', async (t) => {
526545 server . listen ( 0 , ( ) => {
527546 const client = new Client ( `http://localhost:${ server . address ( ) . port } ` )
528547 after ( client . destroy . bind ( client ) )
529- guardDisconnect ( client , t )
548+ client . on ( 'disconnect' , ( ) => {
549+ if ( ! client . closed && ! client . destroyed ) {
550+ t . fail ( 'unexpected disconnect' )
551+ }
552+ } )
530553
531554 const pt = new PassThrough ( )
532555 const signal = new EE ( )
@@ -587,7 +610,11 @@ test('trailers', async (t) => {
587610 server . listen ( 0 , ( ) => {
588611 const client = new Client ( `http://localhost:${ server . address ( ) . port } ` )
589612 after ( ( ) => client . close ( ) )
590- guardDisconnect ( client , t )
613+ client . on ( 'disconnect' , ( ) => {
614+ if ( ! client . closed && ! client . destroyed ) {
615+ t . fail ( 'unexpected disconnect' )
616+ }
617+ } )
591618
592619 client . stream ( {
593620 path : '/' ,
@@ -613,7 +640,11 @@ test('stream ignore 1xx', async (t) => {
613640 server . listen ( 0 , ( ) => {
614641 const client = new Client ( `http://localhost:${ server . address ( ) . port } ` )
615642 after ( ( ) => client . close ( ) )
616- guardDisconnect ( client , t )
643+ client . on ( 'disconnect' , ( ) => {
644+ if ( ! client . closed && ! client . destroyed ) {
645+ t . fail ( 'unexpected disconnect' )
646+ }
647+ } )
617648
618649 let buf = ''
619650 client . stream ( {
@@ -646,7 +677,11 @@ test('stream ignore 1xx and use onInfo', async (t) => {
646677 server . listen ( 0 , ( ) => {
647678 const client = new Client ( `http://localhost:${ server . address ( ) . port } ` )
648679 after ( ( ) => client . close ( ) )
649- guardDisconnect ( client , t )
680+ client . on ( 'disconnect' , ( ) => {
681+ if ( ! client . closed && ! client . destroyed ) {
682+ t . fail ( 'unexpected disconnect' )
683+ }
684+ } )
650685
651686 let buf = ''
652687 client . stream ( {
@@ -685,7 +720,11 @@ test('stream backpressure', async (t) => {
685720 server . listen ( 0 , ( ) => {
686721 const client = new Client ( `http://localhost:${ server . address ( ) . port } ` )
687722 after ( ( ) => client . close ( ) )
688- guardDisconnect ( client , t )
723+ client . on ( 'disconnect' , ( ) => {
724+ if ( ! client . closed && ! client . destroyed ) {
725+ t . fail ( 'unexpected disconnect' )
726+ }
727+ } )
689728
690729 let buf = ''
691730 client . stream ( {
@@ -747,7 +786,11 @@ test('stream needDrain', async (t) => {
747786 after ( ( ) => {
748787 client . destroy ( )
749788 } )
750- guardDisconnect ( client , t )
789+ client . on ( 'disconnect' , ( ) => {
790+ if ( ! client . closed && ! client . destroyed ) {
791+ t . fail ( 'unexpected disconnect' )
792+ }
793+ } )
751794
752795 const dst = new PassThrough ( )
753796 dst . pause ( )
@@ -804,7 +847,11 @@ test('stream legacy needDrain', async (t) => {
804847 after ( ( ) => {
805848 client . destroy ( )
806849 } )
807- guardDisconnect ( client , t )
850+ client . on ( 'disconnect' , ( ) => {
851+ if ( ! client . closed && ! client . destroyed ) {
852+ t . fail ( 'unexpected disconnect' )
853+ }
854+ } )
808855
809856 const dst = new PassThrough ( )
810857 dst . pause ( )
0 commit comments