Skip to content

Commit

Permalink
fix(runtime/testing): format aggregate errors
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervonb committed Sep 22, 2021
1 parent f27902e commit a243343
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
6 changes: 6 additions & 0 deletions cli/tests/integration/test_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
14 changes: 14 additions & 0 deletions cli/tests/testdata/test/aggregate_error.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Check [WILDCARD]/testdata/test/aggregate_error.ts
running 1 test from [WILDCARD]/testdata/test/aggregate_error.ts
test aggregate ... FAILED ([WILDCARD])

failures:

aggregate
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]

6 changes: 6 additions & 0 deletions cli/tests/testdata/test/aggregate_error.ts
Original file line number Diff line number Diff line change
@@ -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]);
});
15 changes: 13 additions & 2 deletions runtime/js/40_testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ finishing test case.`;
ArrayPrototypePush(tests, testDef);
}

function formatFailure(error) {
if (error.errors) {
return {
failed: error.errors.map((error) => inspectArgs([error])).join("\n"),
};
}

return { failed: inspectArgs([error]) };
}

function createTestFilter(filter) {
return (def) => {
if (filter) {
Expand Down Expand Up @@ -213,10 +223,11 @@ finishing test case.`;

try {
await fn();
return "ok";
} catch (error) {
return { "failed": inspectArgs([error]) };
return formatFailure(error);
}

return "ok";
}

function getTestOrigin() {
Expand Down

0 comments on commit a243343

Please sign in to comment.