summaryrefslogtreecommitdiff
path: root/tests/specs/node
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-05-14 19:51:51 -0400
committerGitHub <noreply@github.com>2024-05-14 23:51:51 +0000
commit1a788b58a0e80c4504a0fdf5d47db41c46dc8d37 (patch)
tree4b780c3a09d92c18a381a25d7213828721c05b1f /tests/specs/node
parente389917535e8e7ef13920a96f9c9c1e1ec2b2c55 (diff)
chore: fix flaky rejection_handled_web_process (#23817)
Closes https://github.com/denoland/deno/issues/23712
Diffstat (limited to 'tests/specs/node')
-rw-r--r--tests/specs/node/rejection_handled_web_process/__test__.jsonc6
-rw-r--r--tests/specs/node/rejection_handled_web_process/rejection_handled_web_process.ts35
-rw-r--r--tests/specs/node/rejection_handled_web_process/rejection_handled_web_process.ts.out6
3 files changed, 47 insertions, 0 deletions
diff --git a/tests/specs/node/rejection_handled_web_process/__test__.jsonc b/tests/specs/node/rejection_handled_web_process/__test__.jsonc
new file mode 100644
index 000000000..8f60df4f5
--- /dev/null
+++ b/tests/specs/node/rejection_handled_web_process/__test__.jsonc
@@ -0,0 +1,6 @@
+// Ensure that Web `onrejectionhandled` is fired before
+// Node's `process.on('rejectionHandled')`.
+{
+ "args": "run -A --quiet rejection_handled_web_process.ts",
+ "output": "rejection_handled_web_process.ts.out"
+}
diff --git a/tests/specs/node/rejection_handled_web_process/rejection_handled_web_process.ts b/tests/specs/node/rejection_handled_web_process/rejection_handled_web_process.ts
new file mode 100644
index 000000000..c7957082f
--- /dev/null
+++ b/tests/specs/node/rejection_handled_web_process/rejection_handled_web_process.ts
@@ -0,0 +1,35 @@
+import chalk from "npm:chalk";
+import process from "node:process";
+
+console.log(chalk.red("Hello world!"));
+
+const { promise, resolve } = Promise.withResolvers();
+
+globalThis.addEventListener("unhandledrejection", (e) => {
+ console.log('globalThis.addEventListener("unhandledrejection");');
+ e.preventDefault();
+});
+
+globalThis.addEventListener("rejectionhandled", (_) => {
+ console.log("Web rejectionhandled");
+});
+
+process.on("rejectionHandled", (_) => {
+ console.log("Node rejectionHandled");
+ resolve();
+});
+
+const a = Promise.reject(1);
+setTimeout(() => {
+ a.catch(() => console.log("Added catch handler to the promise"));
+}, 100);
+
+const exitTimeout = setTimeout(() => {
+ console.error("timeout expired");
+ Deno.exit(1);
+}, 30_000);
+
+promise.then(() => {
+ console.log("Success");
+ clearTimeout(exitTimeout);
+});
diff --git a/tests/specs/node/rejection_handled_web_process/rejection_handled_web_process.ts.out b/tests/specs/node/rejection_handled_web_process/rejection_handled_web_process.ts.out
new file mode 100644
index 000000000..e6fefede2
--- /dev/null
+++ b/tests/specs/node/rejection_handled_web_process/rejection_handled_web_process.ts.out
@@ -0,0 +1,6 @@
+Hello world!
+globalThis.addEventListener("unhandledrejection");
+Added catch handler to the promise
+Web rejectionhandled
+Node rejectionHandled
+Success