diff options
| author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-01-12 23:10:42 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-12 22:10:42 +0000 |
| commit | 7471587d29096a8de95a530f2132214ab9c08afa (patch) | |
| tree | d9de4d8e894f7c744c75029898bc1fdd850a758a /cli/tests/testdata | |
| parent | 288774c5eda35c27db21526bbcc94488c534137c (diff) | |
feat: "rejectionhandled" Web event and "rejectionHandled" Node event (#21875)
This commit adds support for "rejectionhandled" Web Event and
"rejectionHandled" Node event.
```js
import process from "node:process";
process.on("rejectionHandled", (promise) => {
console.log("rejectionHandled", reason, promise);
});
window.addEventListener("rejectionhandled", (event) => {
console.log("rejectionhandled", event.reason, event.promise);
});
```
---------
Co-authored-by: Matt Mastracci <matthew@mastracci.com>
Diffstat (limited to 'cli/tests/testdata')
4 files changed, 55 insertions, 0 deletions
diff --git a/cli/tests/testdata/node/rejection_handled_web_process.ts b/cli/tests/testdata/node/rejection_handled_web_process.ts new file mode 100644 index 000000000..00d943feb --- /dev/null +++ b/cli/tests/testdata/node/rejection_handled_web_process.ts @@ -0,0 +1,26 @@ +import chalk from "npm:chalk"; +import process from "node:process"; + +console.log(chalk.red("Hello world!")); + +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"); +}); + +const a = Promise.reject(1); +setTimeout(() => { + a.catch(() => console.log("Added catch handler to the promise")); +}, 10); + +setTimeout(() => { + console.log("Success"); +}, 50); diff --git a/cli/tests/testdata/node/rejection_handled_web_process.ts.out b/cli/tests/testdata/node/rejection_handled_web_process.ts.out new file mode 100644 index 000000000..3a4e2ac23 --- /dev/null +++ b/cli/tests/testdata/node/rejection_handled_web_process.ts.out @@ -0,0 +1,7 @@ +[WILDCARD] +Hello world! +globalThis.addEventListener("unhandledrejection"); +Added catch handler to the promise +Web rejectionhandled +Node rejectionHandled +Success diff --git a/cli/tests/testdata/run/rejection_handled.out b/cli/tests/testdata/run/rejection_handled.out new file mode 100644 index 000000000..5c06fcd2b --- /dev/null +++ b/cli/tests/testdata/run/rejection_handled.out @@ -0,0 +1,5 @@ +[WILDCARD] +unhandledrejection 1 Promise { <rejected> 1 } +Added catch handler to the promise +rejectionhandled 1 Promise { <rejected> 1 } +Success diff --git a/cli/tests/testdata/run/rejection_handled.ts b/cli/tests/testdata/run/rejection_handled.ts new file mode 100644 index 000000000..f058ff966 --- /dev/null +++ b/cli/tests/testdata/run/rejection_handled.ts @@ -0,0 +1,17 @@ +window.addEventListener("unhandledrejection", (event) => { + console.log("unhandledrejection", event.reason, event.promise); + event.preventDefault(); +}); + +window.addEventListener("rejectionhandled", (event) => { + console.log("rejectionhandled", event.reason, event.promise); +}); + +const a = Promise.reject(1); +setTimeout(async () => { + a.catch(() => console.log("Added catch handler to the promise")); +}, 10); + +setTimeout(() => { + console.log("Success"); +}, 50); |
