diff options
Diffstat (limited to 'cli/tests')
5 files changed, 65 insertions, 0 deletions
diff --git a/cli/tests/integration/node_unit_tests.rs b/cli/tests/integration/node_unit_tests.rs index 2cde51552..7c524eb8b 100644 --- a/cli/tests/integration/node_unit_tests.rs +++ b/cli/tests/integration/node_unit_tests.rs @@ -5,6 +5,7 @@ use std::process::Stdio; use std::time::Duration; use std::time::Instant; use test_util as util; +use util::env_vars_for_npm_tests; util::unit_test_factory!( node_unit_test, @@ -157,3 +158,20 @@ fn node_unit_test(test: String) { assert!(status.success()); } + +// Regression test for https://github.com/denoland/deno/issues/16928 +itest!(unhandled_rejection_web { + args: "run -A node/unhandled_rejection_web.ts", + output: "node/unhandled_rejection_web.ts.out", + envs: env_vars_for_npm_tests(), + http_server: true, +}); + +// Ensure that Web `onunhandledrejection` is fired before +// Node's `process.on('unhandledRejection')`. +itest!(unhandled_rejection_web_process { + args: "run -A node/unhandled_rejection_web_process.ts", + output: "node/unhandled_rejection_web_process.ts.out", + envs: env_vars_for_npm_tests(), + http_server: true, +}); 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 |