Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace util.inspect with a custom stack parser #5700

Merged
merged 19 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
66d0e6b
feat: replace util.inspect with custom stack trace parser
galargh Sep 4, 2024
0aa3536
test: add unit tests for the newly added formatters
galargh Sep 4, 2024
778cf03
docs: update README
galargh Sep 4, 2024
a67c887
test: regenerate test fixtures
galargh Sep 4, 2024
e03c707
feat: add support for AggregateError formatting
galargh Sep 4, 2024
b94c936
feat: truncate error chain after 3 levels
galargh Sep 4, 2024
4a2e2b8
Merge branch 'v-next' into galargh/test-reporter-stack
galargh Sep 8, 2024
9f2382a
docs: explain context and location parts of the stack reference
galargh Sep 9, 2024
e651ce6
chore: add support for multi-line error messages back
galargh Sep 9, 2024
d041781
docs: reword how the error message is parsed and formatted
galargh Sep 9, 2024
4a33939
docs: document that we remove [ERR_ASSERTION] from the error message
galargh Sep 9, 2024
f813993
chore: display stack lines not matched as reference as is
galargh Sep 9, 2024
8e72744
chore: turn magic numbers in error formatting into constants
galargh Sep 9, 2024
c1825b8
docs: add more information about aggregate error serialization
galargh Sep 9, 2024
a574309
docs: document stack reference regex in more detail
galargh Sep 9, 2024
3b5d23d
chore: do not remove cwd from the middle of a location string
galargh Sep 9, 2024
71061f4
chore: remove nop.ts
galargh Sep 9, 2024
8ce2547
docs: added suggested comment to a test case
galargh Sep 9, 2024
90ed93a
Merge branch 'v-next' into galargh/test-reporter-stack
galargh Sep 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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