Skip to content

Commit

Permalink
Merge pull request #5700 from NomicFoundation/galargh/test-reporter-s…
Browse files Browse the repository at this point in the history
…tack

feat: replace util.inspect with a custom stack parser
  • Loading branch information
galargh authored Sep 9, 2024
2 parents 582ace9 + 90ed93a commit ca5c057
Show file tree
Hide file tree
Showing 24 changed files with 3,333 additions and 3,003 deletions.
10 changes: 6 additions & 4 deletions v-next/hardhat-node-test-reporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ This reporter will indicate nesting of test suites by indenting the output at 2-

This reporter will format errors in a human readable way.

It will try to use the `inspect` method from the `node:util` module to print the error object together with its stack trace.
It will:

It will replace file URLs with relative paths. This currently does not work well on Windows.

Finally, it will attempt to show a diff of the expected and actual values of the error object, if they are available.
- try to print the error object together with its stack trace;
- try to print the diff of the expected and actual values of the error object, if they are available;
- print internal errors of aggregated errors;
- truncate error cause stack traces after 3 levels;
- replace file URLs with relative paths (this should work on Windows, too).

### Diagnostics

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

1) aggregate error in top level test

2) error with circular cause in top level test


0 passing (520ms)
2 failing

1) aggregate error in top level test:

AggregateError: All promises were rejected
[inner]: Error: Promise 1 failed
 at TestContext.<anonymous> (integration-tests/fixture-tests/errors-test/test.ts:5:5)
 at Test.runInAsyncScope (node:async_hooks:206:9)
 at Test.run (node:internal/test_runner/test:856:25)
 at Test.processPendingSubtests (node:internal/test_runner/test:565:18)
 at node:internal/test_runner/harness:248:12
 at node:internal/process/task_queues:140:7
 at AsyncResource.runInAsyncScope (node:async_hooks:206:9)
 at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
[cause]: Error: Promise 1 cause
 at TestContext.<anonymous> (integration-tests/fixture-tests/errors-test/test.ts:6:14)
 at Test.runInAsyncScope (node:async_hooks:206:9)
 at Test.run (node:internal/test_runner/test:856:25)
 at Test.processPendingSubtests (node:internal/test_runner/test:565:18)
 at node:internal/test_runner/harness:248:12
 at node:internal/process/task_queues:140:7
 at AsyncResource.runInAsyncScope (node:async_hooks:206:9)
 at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
[cause]: AggregateError
 at TestContext.<anonymous> (integration-tests/fixture-tests/errors-test/test.ts:7:16)
 at Test.runInAsyncScope (node:async_hooks:206:9)
 at Test.run (node:internal/test_runner/test:856:25)
 at Test.processPendingSubtests (node:internal/test_runner/test:565:18)
 at node:internal/test_runner/harness:248:12
 at node:internal/process/task_queues:140:7
 at AsyncResource.runInAsyncScope (node:async_hooks:206:9)
 at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
[inner]: Error: Promise 2 failed
 at TestContext.<anonymous> (integration-tests/fixture-tests/errors-test/test.ts:11:35)
 at Test.runInAsyncScope (node:async_hooks:206:9)
 at Test.run (node:internal/test_runner/test:856:25)
 at Test.processPendingSubtests (node:internal/test_runner/test:565:18)
 at node:internal/test_runner/harness:248:12
 at node:internal/process/task_queues:140:7
 at AsyncResource.runInAsyncScope (node:async_hooks:206:9)
 at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)

2) error with circular cause in top level test:

Error: circular error
 at TestContext.<anonymous> (integration-tests/fixture-tests/errors-test/test.ts:17:17)
 at Test.runInAsyncScope (node:async_hooks:206:9)
 at Test.run (node:internal/test_runner/test:856:25)
 at Test.processPendingSubtests (node:internal/test_runner/test:565:18)
 at Test.postRun (node:internal/test_runner/test:955:19)
 at Test.run (node:internal/test_runner/test:898:12)
 at async Test.processPendingSubtests (node:internal/test_runner/test:565:7)
[cause]: Error: circular error
 at TestContext.<anonymous> (integration-tests/fixture-tests/errors-test/test.ts:17:17)
 at Test.runInAsyncScope (node:async_hooks:206:9)
 at Test.run (node:internal/test_runner/test:856:25)
 at Test.processPendingSubtests (node:internal/test_runner/test:565:18)
 at Test.postRun (node:internal/test_runner/test:955:19)
 at Test.run (node:internal/test_runner/test:898:12)
 at async Test.processPendingSubtests (node:internal/test_runner/test:565:7)
[cause]: Error: circular error
 at TestContext.<anonymous> (integration-tests/fixture-tests/errors-test/test.ts:17:17)
 at Test.runInAsyncScope (node:async_hooks:206:9)
 at Test.run (node:internal/test_runner/test:856:25)
 at Test.processPendingSubtests (node:internal/test_runner/test:565:18)
 at Test.postRun (node:internal/test_runner/test:955:19)
 at Test.run (node:internal/test_runner/test:898:12)
 at async Test.processPendingSubtests (node:internal/test_runner/test:565:7)
[cause]: The error chain has been truncated because it's too long (limit: 3)

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { test } from "node:test";

test("aggregate error in top level test", async () => {
const promise1 = Promise.reject(
new Error("Promise 1 failed", {
cause: new Error("Promise 1 cause", {
cause: new AggregateError([new Error("A"), new Error("B")]),
}),
}),
);
const promise2 = Promise.reject(new Error("Promise 2 failed"));

return Promise.any([promise1, promise2]);
});

test("error with circular cause in top level test", async () => {
const error = new Error("circular error");
error.cause = error;
throw error;
});
Loading

0 comments on commit ca5c057

Please sign in to comment.