summaryrefslogtreecommitdiff
path: root/tests/specs/test/exit_code2
diff options
context:
space:
mode:
authorLuke Edwards <lukeed@github.com>2024-05-29 16:16:27 -0700
committerGitHub <noreply@github.com>2024-05-29 23:16:27 +0000
commit13723f267eb87f8c28ef0769cdf7e233b971326e (patch)
treefd97b4c13889aa657601440678f2e31316d8e47d /tests/specs/test/exit_code2
parentcf611fbf548ea0bbd38c82ab02249b7a2aa3b3c9 (diff)
feat: Add `Deno.exitCode` API (#23609)
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 <biwanczuk@gmail.com>
Diffstat (limited to 'tests/specs/test/exit_code2')
-rw-r--r--tests/specs/test/exit_code2/__test__.jsonc5
-rw-r--r--tests/specs/test/exit_code2/main.js7
-rw-r--r--tests/specs/test/exit_code2/main.out25
3 files changed, 37 insertions, 0 deletions
diff --git a/tests/specs/test/exit_code2/__test__.jsonc b/tests/specs/test/exit_code2/__test__.jsonc
new file mode 100644
index 000000000..37d678453
--- /dev/null
+++ b/tests/specs/test/exit_code2/__test__.jsonc
@@ -0,0 +1,5 @@
+{
+ "args": "test main.js",
+ "exitCode": 1,
+ "output": "main.out"
+}
diff --git a/tests/specs/test/exit_code2/main.js b/tests/specs/test/exit_code2/main.js
new file mode 100644
index 000000000..2e6398a58
--- /dev/null
+++ b/tests/specs/test/exit_code2/main.js
@@ -0,0 +1,7 @@
+Deno.test("Deno.exitCode", () => {
+ Deno.exitCode = 5;
+ throw new Error("");
+});
+
+Deno.test("success", () => {
+});
diff --git a/tests/specs/test/exit_code2/main.out b/tests/specs/test/exit_code2/main.out
new file mode 100644
index 000000000..adc9cb577
--- /dev/null
+++ b/tests/specs/test/exit_code2/main.out
@@ -0,0 +1,25 @@
+running 2 tests from ./main.js
+Deno.exitCode ... FAILED ([WILDCARD])
+success ... FAILED ([WILDCARD])
+
+ ERRORS
+
+Deno.exitCode => ./main.js:1:6
+error: Error
+ throw new Error("");
+ ^
+ at [WILDCARD]/exit_code2/main.js:3:9
+
+success => ./main.js:6:6
+error: Error: Test case finished with exit code set to 5.
+ at exitSanitizer (ext:cli/40_test.js:113:15)
+ at async outerWrapped (ext:cli/40_test.js:134:14)
+
+ FAILURES
+
+Deno.exitCode => ./main.js:1:6
+success => ./main.js:6:6
+
+FAILED | 0 passed | 2 failed ([WILDCARD])
+
+error: Test failed