diff --git a/test/es-module/test-esm-tla-unfinished.mjs b/test/es-module/test-esm-tla-unfinished.mjs index 8061d6149cd08f..6660a13a6b5a8d 100644 --- a/test/es-module/test-esm-tla-unfinished.mjs +++ b/test/es-module/test-esm-tla-unfinished.mjs @@ -72,31 +72,24 @@ describe('ESM: unsettled and rejected promises', { concurrency: !process.env.TES }); it('should exit for an unsettled TLA promise with warning', async () => { - const { code, stderr } = await spawnPromisified(execPath, [ + const { code, stderr, stdout } = await spawnPromisified(execPath, [ fixtures.path('es-modules/tla/unresolved.mjs'), ]); - assert.match(stderr, /Warning: Detected unsettled top-level await at.+unresolved\.mjs:5/); + assert.match(stderr, /Warning: Detected unsettled top-level await at.+unresolved\.mjs:1/); assert.match(stderr, /await new Promise/); - assert.strictEqual(code, 13); - }); - - it('the process exit event should provide the correct code for an unsettled TLA promise', async () => { - const { code, stdout } = await spawnPromisified(execPath, [ - fixtures.path('es-modules/tla/unresolved.mjs'), - ]); - - assert.strictEqual(stdout, 'the exit listener received code: 13\n'); + assert.strictEqual(stdout, ''); assert.strictEqual(code, 13); }); it('should exit for an unsettled TLA promise without warning', async () => { - const { code, stderr } = await spawnPromisified(execPath, [ + const { code, stderr, stdout } = await spawnPromisified(execPath, [ '--no-warnings', fixtures.path('es-modules/tla/unresolved.mjs'), ]); assert.strictEqual(stderr, ''); + assert.strictEqual(stdout, ''); assert.strictEqual(code, 13); }); @@ -112,22 +105,13 @@ describe('ESM: unsettled and rejected promises', { concurrency: !process.env.TES }); it('should exit for an unsettled TLA promise and respect explicit exit code via stdin', async () => { - const { code, stderr } = await spawnPromisified(execPath, [ + const { code, stderr, stdout } = await spawnPromisified(execPath, [ '--no-warnings', fixtures.path('es-modules/tla/unresolved-withexitcode.mjs'), ]); assert.strictEqual(stderr, ''); - assert.strictEqual(code, 42); - }); - - it('should exit for an unsettled TLA promise and respect explicit exit code in process exit event', async () => { - const { code, stdout } = await spawnPromisified(execPath, [ - '--no-warnings', - fixtures.path('es-modules/tla/unresolved-withexitcode.mjs'), - ]); - - assert.strictEqual(stdout, 'the exit listener received code: 42\n'); + assert.strictEqual(stdout, ''); assert.strictEqual(code, 42); }); @@ -174,4 +158,25 @@ describe('ESM: unsettled and rejected promises', { concurrency: !process.env.TES assert.strictEqual(stdout, ''); assert.strictEqual(code, 13); }); + + describe('with exit listener', () => { + it('the process exit event should provide the correct code', async () => { + const { code, stdout } = await spawnPromisified(execPath, [ + fixtures.path('es-modules/tla/unresolved-with-listener.mjs'), + ]); + + assert.strictEqual(stdout, 'the exit listener received code: 13\n'); + assert.strictEqual(code, 13); + }); + + it('should exit for an unsettled TLA promise and respect explicit exit code in process exit event', async () => { + const { code, stdout } = await spawnPromisified(execPath, [ + '--no-warnings', + fixtures.path('es-modules/tla/unresolved-withexitcode-and-listener.mjs'), + ]); + + assert.strictEqual(stdout, 'the exit listener received code: 42\n'); + assert.strictEqual(code, 42); + }); + }); }); diff --git a/test/fixtures/es-modules/tla/unresolved-with-listener.mjs b/test/fixtures/es-modules/tla/unresolved-with-listener.mjs new file mode 100644 index 00000000000000..37566bd5688fb5 --- /dev/null +++ b/test/fixtures/es-modules/tla/unresolved-with-listener.mjs @@ -0,0 +1,5 @@ +process.on('exit', (exitCode) => { + console.log(`the exit listener received code: ${exitCode}`); +}) + +await new Promise(() => {}); diff --git a/test/fixtures/es-modules/tla/unresolved-withexitcode-and-listener.mjs b/test/fixtures/es-modules/tla/unresolved-withexitcode-and-listener.mjs new file mode 100644 index 00000000000000..0316dae1cd9a3c --- /dev/null +++ b/test/fixtures/es-modules/tla/unresolved-withexitcode-and-listener.mjs @@ -0,0 +1,7 @@ +process.on('exit', (exitCode) => { + console.log(`the exit listener received code: ${exitCode}`); +}); + +process.exitCode = 42; + +await new Promise(() => {}); diff --git a/test/fixtures/es-modules/tla/unresolved-withexitcode.mjs b/test/fixtures/es-modules/tla/unresolved-withexitcode.mjs index 0316dae1cd9a3c..1cb982311080b8 100644 --- a/test/fixtures/es-modules/tla/unresolved-withexitcode.mjs +++ b/test/fixtures/es-modules/tla/unresolved-withexitcode.mjs @@ -1,7 +1,2 @@ -process.on('exit', (exitCode) => { - console.log(`the exit listener received code: ${exitCode}`); -}); - process.exitCode = 42; - await new Promise(() => {}); diff --git a/test/fixtures/es-modules/tla/unresolved.mjs b/test/fixtures/es-modules/tla/unresolved.mjs index 37566bd5688fb5..231a8cd634825c 100644 --- a/test/fixtures/es-modules/tla/unresolved.mjs +++ b/test/fixtures/es-modules/tla/unresolved.mjs @@ -1,5 +1 @@ -process.on('exit', (exitCode) => { - console.log(`the exit listener received code: ${exitCode}`); -}) - await new Promise(() => {});