From 13723f267eb87f8c28ef0769cdf7e233b971326e Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Wed, 29 May 2024 16:16:27 -0700 Subject: feat: Add `Deno.exitCode` API (#23609) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commits adds the ability to set a would-be exit code for the Deno process without forcing an immediate exit, through the new `Deno.exitCode` API. - **Implements `Deno.exitCode` getter and setter**: Adds support for setting and retrieving a would-be exit code via `Deno.exitCode`. This allows for asynchronous cleanup before process termination without immediately exiting. - **Ensures type safety**: The setter for `Deno.exitCode` validates that the provided value is a number, throwing a TypeError if not, to ensure that only valid exit codes are set. Closes to #23605 --------- Co-authored-by: Bartek IwaƄczuk --- tests/unit_node/process_test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'tests/unit_node/process_test.ts') diff --git a/tests/unit_node/process_test.ts b/tests/unit_node/process_test.ts index 8f56c92a0..5e2fb69c2 100644 --- a/tests/unit_node/process_test.ts +++ b/tests/unit_node/process_test.ts @@ -787,10 +787,10 @@ Deno.test("process.exitCode", () => { assertEquals(process.exitCode, undefined); process.exitCode = 127; assertEquals(process.exitCode, 127); - // deno-lint-ignore no-explicit-any - (process.exitCode as any) = "asdf"; - // deno-lint-ignore no-explicit-any - assertEquals(process.exitCode as any, "asdf"); + assertThrows(() => { + // deno-lint-ignore no-explicit-any + (process.exitCode as any) = "asdf"; + }); // deno-lint-ignore no-explicit-any (process.exitCode as any) = "10"; process.exitCode = undefined; // reset @@ -827,7 +827,7 @@ Deno.test("process.exitCode in should change exit code", async () => { ); await exitCodeTest( "import process from 'node:process'; process.exitCode = NaN;", - 0, + 1, ); }); -- cgit v1.2.3