@@ -72,24 +72,31 @@ describe('ESM: unsettled and rejected promises', { concurrency: !process.env.TES
7272  } ) ; 
7373
7474  it ( 'should exit for an unsettled TLA promise with warning' ,  async  ( )  =>  { 
75-     const  {  code,  stderr,  stdout  }  =  await  spawnPromisified ( execPath ,  [ 
75+     const  {  code,  stderr }  =  await  spawnPromisified ( execPath ,  [ 
7676      fixtures . path ( 'es-modules/tla/unresolved.mjs' ) , 
7777    ] ) ; 
7878
79-     assert . match ( stderr ,  / W a r n i n g :   D e t e c t e d   u n s e t t l e d   t o p - l e v e l   a w a i t   a t .+ u n r e s o l v e d \. m j s : 1 / ) ; 
79+     assert . match ( stderr ,  / W a r n i n g :   D e t e c t e d   u n s e t t l e d   t o p - l e v e l   a w a i t   a t .+ u n r e s o l v e d \. m j s : 5 / ) ; 
8080    assert . match ( stderr ,  / a w a i t   n e w   P r o m i s e / ) ; 
81-     assert . strictEqual ( stdout ,  '' ) ; 
81+     assert . strictEqual ( code ,  13 ) ; 
82+   } ) ; 
83+ 
84+   it ( 'the process exit event should provide the correct code for an unsettled TLA promise' ,  async  ( )  =>  { 
85+     const  {  code,  stdout }  =  await  spawnPromisified ( execPath ,  [ 
86+       fixtures . path ( 'es-modules/tla/unresolved.mjs' ) , 
87+     ] ) ; 
88+ 
89+     assert . strictEqual ( stdout ,  'the exit listener received code: 13\n' ) ; 
8290    assert . strictEqual ( code ,  13 ) ; 
8391  } ) ; 
8492
8593  it ( 'should exit for an unsettled TLA promise without warning' ,  async  ( )  =>  { 
86-     const  {  code,  stderr,  stdout  }  =  await  spawnPromisified ( execPath ,  [ 
94+     const  {  code,  stderr }  =  await  spawnPromisified ( execPath ,  [ 
8795      '--no-warnings' , 
8896      fixtures . path ( 'es-modules/tla/unresolved.mjs' ) , 
8997    ] ) ; 
9098
9199    assert . strictEqual ( stderr ,  '' ) ; 
92-     assert . strictEqual ( stdout ,  '' ) ; 
93100    assert . strictEqual ( code ,  13 ) ; 
94101  } ) ; 
95102
@@ -105,13 +112,22 @@ describe('ESM: unsettled and rejected promises', { concurrency: !process.env.TES
105112  } ) ; 
106113
107114  it ( 'should exit for an unsettled TLA promise and respect explicit exit code via stdin' ,  async  ( )  =>  { 
108-     const  {  code,  stderr,  stdout  }  =  await  spawnPromisified ( execPath ,  [ 
115+     const  {  code,  stderr }  =  await  spawnPromisified ( execPath ,  [ 
109116      '--no-warnings' , 
110117      fixtures . path ( 'es-modules/tla/unresolved-withexitcode.mjs' ) , 
111118    ] ) ; 
112119
113120    assert . strictEqual ( stderr ,  '' ) ; 
114-     assert . strictEqual ( stdout ,  '' ) ; 
121+     assert . strictEqual ( code ,  42 ) ; 
122+   } ) ; 
123+ 
124+   it ( 'should exit for an unsettled TLA promise and respect explicit exit code in process exit event' ,  async  ( )  =>  { 
125+     const  {  code,  stdout }  =  await  spawnPromisified ( execPath ,  [ 
126+       '--no-warnings' , 
127+       fixtures . path ( 'es-modules/tla/unresolved-withexitcode.mjs' ) , 
128+     ] ) ; 
129+ 
130+     assert . strictEqual ( stdout ,  'the exit listener received code: 42\n' ) ; 
115131    assert . strictEqual ( code ,  42 ) ; 
116132  } ) ; 
117133
0 commit comments