summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2022-08-21 19:16:42 +0100
committerGitHub <noreply@github.com>2022-08-21 20:16:42 +0200
commit97954003cc87b664768918173e8d00f6df35e04f (patch)
treedcad94ac57503ba56e8cd14847cc60b1c2ddc91c /cli/tests
parente96933bc163fd81a276cbc169b17f76724a5ac33 (diff)
feat: `queueMicrotask()` error handling (#15522)
Adds error event dispatching for queueMicrotask(). Consequently unhandled errors are now reported with Deno.core.terminate(), which is immune to the existing quirk with plainly thrown errors (#14158).
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/run_tests.rs11
-rw-r--r--cli/tests/testdata/queue_microtask_error.ts5
-rw-r--r--cli/tests/testdata/queue_microtask_error.ts.out6
-rw-r--r--cli/tests/testdata/queue_microtask_error_handled.ts21
-rw-r--r--cli/tests/testdata/queue_microtask_error_handled.ts.out15
5 files changed, 58 insertions, 0 deletions
diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs
index 9c60cc745..8998eecc9 100644
--- a/cli/tests/integration/run_tests.rs
+++ b/cli/tests/integration/run_tests.rs
@@ -2745,6 +2745,17 @@ itest!(report_error_end_of_program {
exit_code: 1,
});
+itest!(queue_microtask_error {
+ args: "run --quiet queue_microtask_error.ts",
+ output: "queue_microtask_error.ts.out",
+ exit_code: 1,
+});
+
+itest!(queue_microtask_error_handled {
+ args: "run --quiet queue_microtask_error_handled.ts",
+ output: "queue_microtask_error_handled.ts.out",
+});
+
itest!(spawn_stdout_inherit {
args: "run --quiet --unstable -A spawn_stdout_inherit.ts",
output: "spawn_stdout_inherit.ts.out",
diff --git a/cli/tests/testdata/queue_microtask_error.ts b/cli/tests/testdata/queue_microtask_error.ts
new file mode 100644
index 000000000..b2e9642c5
--- /dev/null
+++ b/cli/tests/testdata/queue_microtask_error.ts
@@ -0,0 +1,5 @@
+queueMicrotask(() => {
+ throw new Error("foo");
+});
+console.log(1);
+Promise.resolve().then(() => console.log(2));
diff --git a/cli/tests/testdata/queue_microtask_error.ts.out b/cli/tests/testdata/queue_microtask_error.ts.out
new file mode 100644
index 000000000..6c4d41936
--- /dev/null
+++ b/cli/tests/testdata/queue_microtask_error.ts.out
@@ -0,0 +1,6 @@
+1
+error: Uncaught Error: foo
+ throw new Error("foo");
+ ^
+ at [WILDCARD]/queue_microtask_error.ts:2:9
+ at deno:core/[WILDCARD]
diff --git a/cli/tests/testdata/queue_microtask_error_handled.ts b/cli/tests/testdata/queue_microtask_error_handled.ts
new file mode 100644
index 000000000..7d1440135
--- /dev/null
+++ b/cli/tests/testdata/queue_microtask_error_handled.ts
@@ -0,0 +1,21 @@
+addEventListener("error", (event) => {
+ console.log({
+ cancelable: event.cancelable,
+ message: event.message,
+ filename: event.filename,
+ lineno: event.lineno,
+ colno: event.colno,
+ error: event.error,
+ });
+ event.preventDefault();
+});
+
+onerror = (event) => {
+ console.log("onerror() called", event.error);
+};
+
+queueMicrotask(() => {
+ throw new Error("foo");
+});
+console.log(1);
+Promise.resolve().then(() => console.log(2));
diff --git a/cli/tests/testdata/queue_microtask_error_handled.ts.out b/cli/tests/testdata/queue_microtask_error_handled.ts.out
new file mode 100644
index 000000000..7f3f7f84a
--- /dev/null
+++ b/cli/tests/testdata/queue_microtask_error_handled.ts.out
@@ -0,0 +1,15 @@
+1
+{
+ cancelable: true,
+ message: "Uncaught Error: foo",
+ filename: "[WILDCARD]/queue_microtask_error_handled.ts",
+ lineno: 18,
+ colno: 9,
+ error: Error: foo
+ at [WILDCARD]/queue_microtask_error_handled.ts:18:9
+ at deno:core/[WILDCARD]
+}
+onerror() called Error: foo
+ at [WILDCARD]/queue_microtask_error_handled.ts:18:9
+ at deno:core/[WILDCARD]
+2