summaryrefslogtreecommitdiff
path: root/cli/tests/testdata
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-05-24 15:40:41 +0200
committerGitHub <noreply@github.com>2023-05-24 15:40:41 +0200
commit0bb5bbc7a0ff7565a4c7fa4ebc8c69e02f76e6b5 (patch)
treea5ab85f34d7984428288cb8d221cf09851d333bd /cli/tests/testdata
parent787e1f0f92e81f025ec0dfdce2acff15900267fc (diff)
fix(node): fire 'unhandledrejection' event when using node: or npm: imports (#19235)
This commit fixes emitting "unhandledrejection" event when there are "node:" or "npm:" imports. Before this commit the Node "unhandledRejection" event was emitted using a regular listener for Web "unhandledrejection" event. This listener was installed before any user listener had a chance to be installed which effectively prevent emitting "unhandledrejection" events to user code. Closes https://github.com/denoland/deno/issues/16928
Diffstat (limited to 'cli/tests/testdata')
-rw-r--r--cli/tests/testdata/node/unhandled_rejection_web.ts17
-rw-r--r--cli/tests/testdata/node/unhandled_rejection_web.ts.out4
-rw-r--r--cli/tests/testdata/node/unhandled_rejection_web_process.ts21
-rw-r--r--cli/tests/testdata/node/unhandled_rejection_web_process.ts.out5
4 files changed, 47 insertions, 0 deletions
diff --git a/cli/tests/testdata/node/unhandled_rejection_web.ts b/cli/tests/testdata/node/unhandled_rejection_web.ts
new file mode 100644
index 000000000..396c58c2a
--- /dev/null
+++ b/cli/tests/testdata/node/unhandled_rejection_web.ts
@@ -0,0 +1,17 @@
+import chalk from "npm:chalk";
+
+console.log(chalk.red("Hello world!"));
+
+globalThis.addEventListener("unhandledrejection", (e) => {
+ console.log("Handled the promise rejection");
+ e.preventDefault();
+});
+
+// deno-lint-ignore require-await
+(async () => {
+ throw new Error("boom!");
+})();
+
+setTimeout(() => {
+ console.log("Success");
+}, 1000);
diff --git a/cli/tests/testdata/node/unhandled_rejection_web.ts.out b/cli/tests/testdata/node/unhandled_rejection_web.ts.out
new file mode 100644
index 000000000..19db7f90e
--- /dev/null
+++ b/cli/tests/testdata/node/unhandled_rejection_web.ts.out
@@ -0,0 +1,4 @@
+[WILDCARD]
+Hello world!
+Handled the promise rejection
+Success
diff --git a/cli/tests/testdata/node/unhandled_rejection_web_process.ts b/cli/tests/testdata/node/unhandled_rejection_web_process.ts
new file mode 100644
index 000000000..2aaacfbff
--- /dev/null
+++ b/cli/tests/testdata/node/unhandled_rejection_web_process.ts
@@ -0,0 +1,21 @@
+import chalk from "npm:chalk";
+import process from "node:process";
+
+console.log(chalk.red("Hello world!"));
+
+process.on("unhandledRejection", (_e) => {
+ console.log('process.on("unhandledRejection");');
+});
+
+globalThis.addEventListener("unhandledrejection", (_e) => {
+ console.log('globalThis.addEventListener("unhandledrejection");');
+});
+
+// deno-lint-ignore require-await
+(async () => {
+ throw new Error("boom!");
+})();
+
+setTimeout(() => {
+ console.log("Success");
+}, 1000);
diff --git a/cli/tests/testdata/node/unhandled_rejection_web_process.ts.out b/cli/tests/testdata/node/unhandled_rejection_web_process.ts.out
new file mode 100644
index 000000000..ea307474a
--- /dev/null
+++ b/cli/tests/testdata/node/unhandled_rejection_web_process.ts.out
@@ -0,0 +1,5 @@
+[WILDCARD]
+Hello world!
+globalThis.addEventListener("unhandledrejection");
+process.on("unhandledRejection");
+Success