@@ -26,6 +26,8 @@ test('emit error if thread exits', async function (t) {
2626 sync : true
2727 } )
2828
29+ const closed = once ( stream , 'close' ) . catch ( ( ) => { } )
30+
2931 stream . on ( 'ready' , ( ) => {
3032 stream . write ( 'hello world\n' )
3133 } )
@@ -40,6 +42,8 @@ test('emit error if thread exits', async function (t) {
4042 stream . write ( 'noop' ) ;
4143 [ err ] = await once ( stream , 'error' )
4244 assert . strictEqual ( err . message , 'the worker has exited' )
45+
46+ await closed
4347} )
4448
4549test ( 'emit error if thread have unhandledRejection' , async function ( t ) {
@@ -48,6 +52,8 @@ test('emit error if thread have unhandledRejection', async function (t) {
4852 sync : true
4953 } )
5054
55+ const closed = once ( stream , 'close' ) . catch ( ( ) => { } )
56+
5157 stream . on ( 'ready' , ( ) => {
5258 stream . write ( 'hello world\n' )
5359 } )
@@ -62,6 +68,8 @@ test('emit error if thread have unhandledRejection', async function (t) {
6268 stream . write ( 'noop' ) ;
6369 [ err ] = await once ( stream , 'error' )
6470 assert . strictEqual ( err . message , 'the worker has exited' )
71+
72+ await closed
6573} )
6674
6775test ( 'emit error if worker stream emit error' , async function ( t ) {
@@ -70,6 +78,8 @@ test('emit error if worker stream emit error', async function (t) {
7078 sync : true
7179 } )
7280
81+ const closed = once ( stream , 'close' ) . catch ( ( ) => { } )
82+
7383 stream . on ( 'ready' , ( ) => {
7484 stream . write ( 'hello world\n' )
7585 } )
@@ -84,6 +94,8 @@ test('emit error if worker stream emit error', async function (t) {
8494 stream . write ( 'noop' ) ;
8595 [ err ] = await once ( stream , 'error' )
8696 assert . strictEqual ( err . message , 'the worker has exited' )
97+
98+ await closed
8799} )
88100
89101test ( 'emit error if thread have uncaughtException' , async function ( t ) {
@@ -92,6 +104,8 @@ test('emit error if thread have uncaughtException', async function (t) {
92104 sync : true
93105 } )
94106
107+ const closed = once ( stream , 'close' ) . catch ( ( ) => { } )
108+
95109 stream . on ( 'ready' , ( ) => {
96110 stream . write ( 'hello world\n' )
97111 } )
@@ -106,6 +120,8 @@ test('emit error if thread have uncaughtException', async function (t) {
106120 stream . write ( 'noop' ) ;
107121 [ err ] = await once ( stream , 'error' )
108122 assert . strictEqual ( err . message , 'the worker has exited' )
123+
124+ await closed
109125} )
110126
111127test ( 'close the work if out of scope on gc' , { skip : ! global . WeakRef } , async function ( t ) {
0 commit comments