-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
process: runtime deprecate coercion to integer in
process.exit()
This is a follow up of doc-only deprecation #43738. Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com PR-URL: #44711 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
Showing
6 changed files
with
171 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
|
||
const deprecated = [ | ||
{ | ||
code: '', | ||
expected: 0, | ||
}, | ||
{ | ||
code: '1 one', | ||
expected: 0, | ||
}, | ||
{ | ||
code: 'two', | ||
expected: 0, | ||
}, | ||
{ | ||
code: {}, | ||
expected: 0, | ||
}, | ||
{ | ||
code: [], | ||
expected: 0, | ||
}, | ||
{ | ||
code: true, | ||
expected: 1, | ||
}, | ||
{ | ||
code: false, | ||
expected: 0, | ||
}, | ||
{ | ||
code: 2n, | ||
expected: 0, | ||
expected_useProcessExitCode: 1, | ||
}, | ||
{ | ||
code: 2.1, | ||
expected: 2, | ||
}, | ||
{ | ||
code: Infinity, | ||
expected: 0, | ||
}, | ||
{ | ||
code: NaN, | ||
expected: 0, | ||
}, | ||
]; | ||
const args = deprecated; | ||
|
||
if (process.argv[2] === undefined) { | ||
const { spawnSync } = require('node:child_process'); | ||
const { inspect, debuglog } = require('node:util'); | ||
const { strictEqual } = require('node:assert'); | ||
|
||
const debug = debuglog('test'); | ||
const node = process.execPath; | ||
const test = (index, useProcessExitCode) => { | ||
const { status: code, stderr } = spawnSync(node, [ | ||
__filename, | ||
index, | ||
useProcessExitCode, | ||
]); | ||
debug(`actual: ${code}, ${inspect(args[index])} ${!!useProcessExitCode}`); | ||
debug(`${stderr}`); | ||
|
||
const expected = | ||
useProcessExitCode && args[index].expected_useProcessExitCode ? | ||
args[index].expected_useProcessExitCode : | ||
args[index].expected; | ||
|
||
strictEqual(code, expected, `actual: ${code}, ${inspect(args[index])}`); | ||
strictEqual( | ||
['[DEP0164]'].some((pattern) => stderr.includes(pattern)), | ||
true | ||
); | ||
}; | ||
|
||
for (const index of args.keys()) { | ||
// Check `process.exit([code])` | ||
test(index); | ||
// Check exit with `process.exitCode` | ||
test(index, true); | ||
} | ||
} else { | ||
const index = parseInt(process.argv[2]); | ||
const useProcessExitCode = process.argv[3] !== 'undefined'; | ||
if (Number.isNaN(index)) { | ||
return process.exit(100); | ||
} | ||
|
||
if (useProcessExitCode) { | ||
process.exitCode = args[index].code; | ||
} else { | ||
process.exit(args[index].code); | ||
} | ||
} |