summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2021-10-01 03:54:56 +0800
committerGitHub <noreply@github.com>2021-09-30 21:54:56 +0200
commit6bf5c850e6b4f6163721bd673b191bda0e0dc0a6 (patch)
treef02e9d3afb10709467531175b4841fb170ac282d
parentc3e441c5b54de09ca3af3e1fd0098e8d307c18d7 (diff)
fix(runtime/testing): format aggregate errors (#12183)
-rw-r--r--cli/tests/integration/test_tests.rs6
-rw-r--r--cli/tests/testdata/test/aggregate_error.out24
-rw-r--r--cli/tests/testdata/test/aggregate_error.ts6
-rw-r--r--runtime/js/40_testing.js22
4 files changed, 56 insertions, 2 deletions
diff --git a/cli/tests/integration/test_tests.rs b/cli/tests/integration/test_tests.rs
index 0baf94422..24ceeefb4 100644
--- a/cli/tests/integration/test_tests.rs
+++ b/cli/tests/integration/test_tests.rs
@@ -180,3 +180,9 @@ itest!(shuffle_with_seed {
exit_code: 0,
output: "test/shuffle.out",
});
+
+itest!(aggregate_error {
+ args: "test test/aggregate_error.ts",
+ exit_code: 1,
+ output: "test/aggregate_error.out",
+});
diff --git a/cli/tests/testdata/test/aggregate_error.out b/cli/tests/testdata/test/aggregate_error.out
new file mode 100644
index 000000000..ed1ee1a94
--- /dev/null
+++ b/cli/tests/testdata/test/aggregate_error.out
@@ -0,0 +1,24 @@
+Check [WILDCARD]/testdata/test/aggregate_error.ts
+running 1 test from [WILDCARD]/testdata/test/aggregate_error.ts
+test aggregate ... FAILED ([WILDCARD])
+
+failures:
+
+aggregate
+AggregateError
+ Error: Error 1
+ at [WILDCARD]/testdata/test/aggregate_error.ts:2:18
+ [WILDCARD]
+ Error: Error 2
+ at [WILDCARD]/testdata/test/aggregate_error.ts:3:18
+ [WILDCARD]
+ at [WILDCARD]/testdata/test/aggregate_error.ts:5:9
+ at [WILDCARD]
+
+failures:
+
+ aggregate
+
+test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD])
+
+error: Test failed
diff --git a/cli/tests/testdata/test/aggregate_error.ts b/cli/tests/testdata/test/aggregate_error.ts
new file mode 100644
index 000000000..0661ea249
--- /dev/null
+++ b/cli/tests/testdata/test/aggregate_error.ts
@@ -0,0 +1,6 @@
+Deno.test("aggregate", function () {
+ const error1 = new Error("Error 1");
+ const error2 = new Error("Error 2");
+
+ throw new AggregateError([error1, error2]);
+});
diff --git a/runtime/js/40_testing.js b/runtime/js/40_testing.js
index 38382f9fd..f4f5373c6 100644
--- a/runtime/js/40_testing.js
+++ b/runtime/js/40_testing.js
@@ -186,6 +186,23 @@ finishing test case.`;
ArrayPrototypePush(tests, testDef);
}
+ function formatFailure(error) {
+ if (error.errors) {
+ const message = error
+ .errors
+ .map((error) =>
+ inspectArgs([error]).replace(/^(?!\s*$)/gm, " ".repeat(4))
+ )
+ .join("\n");
+
+ return {
+ failed: error.name + "\n" + message + error.stack,
+ };
+ }
+
+ return { failed: inspectArgs([error]) };
+ }
+
function createTestFilter(filter) {
return (def) => {
if (filter) {
@@ -213,10 +230,11 @@ finishing test case.`;
try {
await fn();
- return "ok";
} catch (error) {
- return { "failed": inspectArgs([error]) };
+ return formatFailure(error);
}
+
+ return "ok";
}
function getTestOrigin() {