1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -05:00
denoland-deno/cli/tests/testdata/node/unhandled_rejection_web_process.ts
Bartek Iwańczuk 0bb5bbc7a0
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
2023-05-24 15:40:41 +02:00

21 lines
482 B
TypeScript

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);