1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-28 01:59:06 -05:00

fix(runtime/testing): format aggregate errors (#12183)

This commit is contained in:
Casper Beyer 2021-10-01 03:54:56 +08:00 committed by Ryan Dahl
parent b20a779f7b
commit 96530df7fb
4 changed files with 56 additions and 2 deletions

View file

@ -180,3 +180,9 @@ itest!(shuffle_with_seed {
exit_code: 0, exit_code: 0,
output: "test/shuffle.out", output: "test/shuffle.out",
}); });
itest!(aggregate_error {
args: "test test/aggregate_error.ts",
exit_code: 1,
output: "test/aggregate_error.out",
});

View file

@ -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

View file

@ -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]);
});

View file

@ -186,6 +186,23 @@ finishing test case.`;
ArrayPrototypePush(tests, testDef); 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) { function createTestFilter(filter) {
return (def) => { return (def) => {
if (filter) { if (filter) {
@ -213,10 +230,11 @@ finishing test case.`;
try { try {
await fn(); await fn();
return "ok";
} catch (error) { } catch (error) {
return { "failed": inspectArgs([error]) }; return formatFailure(error);
} }
return "ok";
} }
function getTestOrigin() { function getTestOrigin() {