diff options
Diffstat (limited to 'tests/specs')
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 |