mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
e948ef351b
Handle situations in which the main `Promise` from a TLA module is not fulfilled better: - When not resolving the `Promise` at all, set a non-zero exit code (unless another one has been requested explicitly) to distinguish the result from a successful completion. - When rejecting the `Promise`, always treat it like an uncaught exception. In particular, this also ensures a non-zero exit code. Refs: https://github.com/nodejs/node/pull/34558 PR-URL: https://github.com/nodejs/node/pull/34640 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
83 lines
2.6 KiB
JavaScript
83 lines
2.6 KiB
JavaScript
import '../common/index.mjs';
|
|
import assert from 'assert';
|
|
import child_process from 'child_process';
|
|
import fixtures from '../common/fixtures.js';
|
|
|
|
{
|
|
// Unresolved TLA promise, --eval
|
|
const { status, stdout, stderr } = child_process.spawnSync(
|
|
process.execPath,
|
|
['--input-type=module', '--eval', 'await new Promise(() => {})'],
|
|
{ encoding: 'utf8' });
|
|
assert.deepStrictEqual([status, stdout, stderr], [13, '', '']);
|
|
}
|
|
|
|
{
|
|
// Rejected TLA promise, --eval
|
|
const { status, stdout, stderr } = child_process.spawnSync(
|
|
process.execPath,
|
|
['--input-type=module', '-e', 'await Promise.reject(new Error("Xyz"))'],
|
|
{ encoding: 'utf8' });
|
|
assert.deepStrictEqual([status, stdout], [1, '']);
|
|
assert.match(stderr, /Error: Xyz/);
|
|
}
|
|
|
|
{
|
|
// Unresolved TLA promise with explicit exit code, --eval
|
|
const { status, stdout, stderr } = child_process.spawnSync(
|
|
process.execPath,
|
|
['--input-type=module', '--eval',
|
|
'process.exitCode = 42;await new Promise(() => {})'],
|
|
{ encoding: 'utf8' });
|
|
assert.deepStrictEqual([status, stdout, stderr], [42, '', '']);
|
|
}
|
|
|
|
{
|
|
// Rejected TLA promise with explicit exit code, --eval
|
|
const { status, stdout, stderr } = child_process.spawnSync(
|
|
process.execPath,
|
|
['--input-type=module', '-e',
|
|
'process.exitCode = 42;await Promise.reject(new Error("Xyz"))'],
|
|
{ encoding: 'utf8' });
|
|
assert.deepStrictEqual([status, stdout], [1, '']);
|
|
assert.match(stderr, /Error: Xyz/);
|
|
}
|
|
|
|
{
|
|
// Unresolved TLA promise, module file
|
|
const { status, stdout, stderr } = child_process.spawnSync(
|
|
process.execPath,
|
|
[fixtures.path('es-modules/tla/unresolved.mjs')],
|
|
{ encoding: 'utf8' });
|
|
assert.deepStrictEqual([status, stdout, stderr], [13, '', '']);
|
|
}
|
|
|
|
{
|
|
// Rejected TLA promise, module file
|
|
const { status, stdout, stderr } = child_process.spawnSync(
|
|
process.execPath,
|
|
[fixtures.path('es-modules/tla/rejected.mjs')],
|
|
{ encoding: 'utf8' });
|
|
assert.deepStrictEqual([status, stdout], [1, '']);
|
|
assert.match(stderr, /Error: Xyz/);
|
|
}
|
|
|
|
{
|
|
// Unresolved TLA promise, module file
|
|
const { status, stdout, stderr } = child_process.spawnSync(
|
|
process.execPath,
|
|
[fixtures.path('es-modules/tla/unresolved-withexitcode.mjs')],
|
|
{ encoding: 'utf8' });
|
|
assert.deepStrictEqual([status, stdout, stderr], [42, '', '']);
|
|
}
|
|
|
|
{
|
|
// Rejected TLA promise, module file
|
|
const { status, stdout, stderr } = child_process.spawnSync(
|
|
process.execPath,
|
|
[fixtures.path('es-modules/tla/rejected-withexitcode.mjs')],
|
|
{ encoding: 'utf8' });
|
|
assert.deepStrictEqual([status, stdout], [1, '']);
|
|
assert.match(stderr, /Error: Xyz/);
|
|
}
|