summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2022-04-16 16:12:26 +0200
committerGitHub <noreply@github.com>2022-04-16 16:12:26 +0200
commita87be28a46b67e53354f8ce69386057ddbb0f46c (patch)
tree5615afd3ac57821edd7c782cfe33d253777a8aa3 /cli/tests
parent0bb96cde726127291dccb62145e76a50b2efcd2f (diff)
feat: Better formatting for AggregateError (#14285)
This commit adds "aggregated" field to "deno_core::JsError" that stores instances of "JsError" recursively to properly handle "AggregateError" formatting. Appropriate logics was added to "PrettyJsError" and "console" API to format AggregateErrors. Co-authored-by: Nayeem Rahman <nayeemrmn99@gmail.com>
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/run_tests.rs12
-rw-r--r--cli/tests/testdata/aggregate_error.out18
-rw-r--r--cli/tests/testdata/aggregate_error.ts9
-rw-r--r--cli/tests/testdata/complex_error.ts18
-rw-r--r--cli/tests/testdata/complex_error.ts.out44
-rw-r--r--cli/tests/testdata/error_cause.ts.out8
-rw-r--r--cli/tests/testdata/error_cause_recursive.ts.out10
7 files changed, 107 insertions, 12 deletions
diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs
index 969a57a9f..b918e403d 100644
--- a/cli/tests/integration/run_tests.rs
+++ b/cli/tests/integration/run_tests.rs
@@ -2714,3 +2714,15 @@ itest!(set_timeout_error_handled {
args: "run --quiet set_timeout_error_handled.ts",
output: "set_timeout_error_handled.ts.out",
});
+
+itest!(aggregate_error {
+ args: "run --quiet aggregate_error.ts",
+ output: "aggregate_error.out",
+ exit_code: 1,
+});
+
+itest!(complex_error {
+ args: "run --quiet complex_error.ts",
+ output: "complex_error.ts.out",
+ exit_code: 1,
+});
diff --git a/cli/tests/testdata/aggregate_error.out b/cli/tests/testdata/aggregate_error.out
new file mode 100644
index 000000000..7d0c09c70
--- /dev/null
+++ b/cli/tests/testdata/aggregate_error.out
@@ -0,0 +1,18 @@
+AggregateError: Multiple errors.
+ at [WILDCARD]/aggregate_error.ts:1:24
+
+AggregateError: Multiple errors.
+ Error: Error message 1.
+ at [WILDCARD]/aggregate_error.ts:2:3
+ Error: Error message 2.
+ at [WILDCARD]/aggregate_error.ts:3:3
+ at [WILDCARD]/aggregate_error.ts:1:24
+
+error: Uncaught AggregateError: Multiple errors.
+ Error: Error message 1.
+ at [WILDCARD]/aggregate_error.ts:2:3
+ Error: Error message 2.
+ at [WILDCARD]/aggregate_error.ts:3:3
+const aggregateError = new AggregateError([
+ ^
+ at [WILDCARD]/aggregate_error.ts:1:24
diff --git a/cli/tests/testdata/aggregate_error.ts b/cli/tests/testdata/aggregate_error.ts
new file mode 100644
index 000000000..ce4b54376
--- /dev/null
+++ b/cli/tests/testdata/aggregate_error.ts
@@ -0,0 +1,9 @@
+const aggregateError = new AggregateError([
+ new Error("Error message 1."),
+ new Error("Error message 2."),
+], "Multiple errors.");
+console.log(aggregateError.stack);
+console.log();
+console.log(aggregateError);
+console.log();
+throw aggregateError;
diff --git a/cli/tests/testdata/complex_error.ts b/cli/tests/testdata/complex_error.ts
new file mode 100644
index 000000000..b462992ac
--- /dev/null
+++ b/cli/tests/testdata/complex_error.ts
@@ -0,0 +1,18 @@
+const error = new AggregateError(
+ [
+ new AggregateError([new Error("qux1"), new Error("quux1")]),
+ new Error("bar1", { cause: new Error("baz1") }),
+ ],
+ "foo1",
+ {
+ cause: new AggregateError([
+ new AggregateError([new Error("qux2"), new Error("quux2")]),
+ new Error("bar2", { cause: new Error("baz2") }),
+ ], "foo2"),
+ },
+);
+console.log(error.stack);
+console.log();
+console.log(error);
+console.log();
+throw error;
diff --git a/cli/tests/testdata/complex_error.ts.out b/cli/tests/testdata/complex_error.ts.out
new file mode 100644
index 000000000..eef1b7699
--- /dev/null
+++ b/cli/tests/testdata/complex_error.ts.out
@@ -0,0 +1,44 @@
+AggregateError: foo1
+ at [WILDCARD]/complex_error.ts:1:15
+
+AggregateError: foo1
+ AggregateError
+ Error: qux1
+ at [WILDCARD]/complex_error.ts:3:25
+ Error: quux1
+ at [WILDCARD]/complex_error.ts:3:44
+ at [WILDCARD]/complex_error.ts:3:5
+ Error: bar1
+ at [WILDCARD]/complex_error.ts:4:5
+ Caused by Error: baz1
+ at [WILDCARD]/complex_error.ts:4:32
+ at [WILDCARD]/complex_error.ts:1:15
+Caused by AggregateError: foo2
+ at [WILDCARD]/complex_error.ts:8:12
+
+error: Uncaught AggregateError: foo1
+ AggregateError
+ Error: qux1
+ at [WILDCARD]/complex_error.ts:3:25
+ Error: quux1
+ at [WILDCARD]/complex_error.ts:3:44
+ at [WILDCARD]/complex_error.ts:3:5
+ Error: bar1
+ at [WILDCARD]/complex_error.ts:4:5
+ Caused by: Error: baz1
+ at [WILDCARD]/complex_error.ts:4:32
+const error = new AggregateError(
+ ^
+ at [WILDCARD]/complex_error.ts:1:15
+Caused by: AggregateError: foo2
+ AggregateError
+ Error: qux2
+ at [WILDCARD]/complex_error.ts:9:27
+ Error: quux2
+ at [WILDCARD]/complex_error.ts:9:46
+ at [WILDCARD]/complex_error.ts:9:7
+ Error: bar2
+ at [WILDCARD]/complex_error.ts:10:7
+ Caused by: Error: baz2
+ at [WILDCARD]/complex_error.ts:10:34
+ at [WILDCARD]/complex_error.ts:8:12
diff --git a/cli/tests/testdata/error_cause.ts.out b/cli/tests/testdata/error_cause.ts.out
index 0f32b1bdd..512ab4326 100644
--- a/cli/tests/testdata/error_cause.ts.out
+++ b/cli/tests/testdata/error_cause.ts.out
@@ -6,12 +6,10 @@ error: Uncaught Error: foo
at b (file:///[WILDCARD]/error_cause.ts:7:3)
at c (file:///[WILDCARD]/error_cause.ts:11:3)
at file:///[WILDCARD]/error_cause.ts:14:1
-Caused by: Uncaught Error: bar
- throw new Error("foo", { cause: new Error("bar", { cause: "deno" as any }) });
- ^
+Caused by: Error: bar
at a (file:///[WILDCARD]/error_cause.ts:3:35)
at b (file:///[WILDCARD]/error_cause.ts:7:3)
at c (file:///[WILDCARD]/error_cause.ts:11:3)
at file:///[WILDCARD]/error_cause.ts:14:1
-Caused by: Uncaught deno
-[WILDCARD] \ No newline at end of file
+Caused by: deno
+[WILDCARD]
diff --git a/cli/tests/testdata/error_cause_recursive.ts.out b/cli/tests/testdata/error_cause_recursive.ts.out
index 8bfda02fb..ac729574d 100644
--- a/cli/tests/testdata/error_cause_recursive.ts.out
+++ b/cli/tests/testdata/error_cause_recursive.ts.out
@@ -3,12 +3,8 @@ error: Uncaught Error: bar
const y = new Error("bar", { cause: x });
^
at file:///[WILDCARD]/error_cause_recursive.ts:2:11
-Caused by: Uncaught Error: foo
-const x = new Error("foo");
- ^
+Caused by: Error: foo
at file:///[WILDCARD]/error_cause_recursive.ts:1:11
-Caused by: Uncaught Error: bar
-const y = new Error("bar", { cause: x });
- ^
+Caused by: Error: bar
at file:///[WILDCARD]/error_cause_recursive.ts:2:11
-[WILDCARD] \ No newline at end of file
+[WILDCARD]