@@ -174,4 +174,31 @@ describe('ESM: unsettled and rejected promises', { concurrency: !process.env.TES
174174 assert . strictEqual ( stdout , '' ) ;
175175 assert . strictEqual ( code , 13 ) ;
176176 } ) ;
177+
178+ describe ( 'with exit listener' , ( ) => {
179+ it ( 'the process exit event should provide the correct code' , async ( ) => {
180+ const { code, stdout } = await spawnPromisified ( execPath , [
181+ fixtures . path ( 'es-modules/tla/unresolved-with-listener.mjs' ) ,
182+ ] ) ;
183+
184+ assert . strictEqual ( stdout ,
185+ 'the exit listener received code: 13\n' +
186+ 'process.exitCode inside the exist listener: 13\n'
187+ ) ;
188+ assert . strictEqual ( code , 13 ) ;
189+ } ) ;
190+
191+ it ( 'should exit for an unsettled TLA promise and respect explicit exit code in process exit event' , async ( ) => {
192+ const { code, stdout } = await spawnPromisified ( execPath , [
193+ '--no-warnings' ,
194+ fixtures . path ( 'es-modules/tla/unresolved-withexitcode-and-listener.mjs' ) ,
195+ ] ) ;
196+
197+ assert . strictEqual ( stdout ,
198+ 'the exit listener received code: 42\n' +
199+ 'process.exitCode inside the exist listener: 42\n'
200+ ) ;
201+ assert . strictEqual ( code , 42 ) ;
202+ } ) ;
203+ } ) ;
177204} ) ;
0 commit comments