Skip to content

Commit a189ce0

Browse files
aojunhao123SimenB
andauthored
fix(jest-message-util): print inner errors of AggregateError test failures (#16316)
Co-authored-by: Simen Bekkhus <[email protected]>
1 parent 491c9d5 commit a189ce0

28 files changed

Lines changed: 1287 additions & 179 deletions

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,5 @@ crowdin-cli.jar
6262

6363
# We don't want these temp files
6464
packages/jest-worker/src/workers/__tests__/__temp__
65+
66+
.zed

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@
55
- `[@jest/expect-utils, jest-mock]` Add `mockFn.whenCalledWith(...args)` for configuring return values per argument list, with first-class asymmetric-matcher support ([#16053](https://github.com/jestjs/jest/pull/16053))
66
- `[@jest/expect-utils]` Export `AsymmetricMatcher` and `FunctionParameters` types (previously private to `expect`) ([#16053](https://github.com/jestjs/jest/pull/16053))
77
- `[jest-circus, jest-core, jest-jasmine2, jest-test-result, jest-types]` `--collectTests` now expands `test.each`/`describe.each` cases and reports per-status counts (skipped/todo via the new `wouldRun` flag for selected tests) plus a summary line that match a real run, including under `--testNamePattern` and `.only`/`fdescribe` focus on both the circus and jasmine2 runners ([#16259](https://github.com/jestjs/jest/pull/16259))
8+
- `[jest-circus, jest-message-util, jest-reporters, jest-types]` Add `retryMessages` to `AssertionResult` and export `formatErrorStack`, so the retry log renders nested `cause` and `AggregateError` sections with code frames instead of serialized `[cause]:`/`[errors]:` markers ([#16316](https://github.com/jestjs/jest/pull/16316))
9+
- `[jest-circus, jest-types]` Add `unhandledErrorsDetailed` to `Circus.RunResult`, so an unhandled rejection reports its `cause` chain and `AggregateError` entries with code frames instead of a pre-serialized stack ([#16316](https://github.com/jestjs/jest/pull/16316))
810
- `[jest-haste-map]` Replace `NodeWatcher` and `FSEventsWatcher` with `@parcel/watcher` for the non-watchman watch path ([#16188](https://github.com/jestjs/jest/pull/16188))
911
- `[jest-resolve]` Bump `unrs-resolver` to 1.12.1, remove `jest-pnp-resolver` and unnecessary checks ([#15721](https://github.com/jestjs/jest/pull/15721))
1012

1113
### Fixes
1214

1315
- `[expect, jest-message-util, jest-pattern, jest-regex-util, jest-util]` Revert `node:` protocol imports to restore webpack/browser-bundle compatibility ([#16167](https://github.com/jestjs/jest/pull/16167))
1416
- `[expect]` Widen `toMatchObject` and `objectContaining` parameter type from `Record<string, unknown>` to `object` so class instances are accepted ([#16196](https://github.com/jestjs/jest/pull/16196))
17+
- `[jest-circus, jest-jasmine2, jest-message-util]` Serialize the inner errors of an `AggregateError` into `failureMessages`, `retryReasons` and `unhandledErrors`, so `--json` output and reporter annotations include them ([#16316](https://github.com/jestjs/jest/pull/16316))
1518
- `[jest-config]` Add missing `findRelatedTests`, `outputFile`, and `replname` entries to `ValidConfig` so they no longer trigger spurious "Unknown option" warnings ([#16224](https://github.com/jestjs/jest/pull/16224))
1619
- `[jest-haste-map]` Keep watch mode alive when an outside process briefly makes a file unreadable on Windows, instead of tearing the watcher down on `EPERM` ([#16295](https://github.com/jestjs/jest/pull/16295))
20+
- `[jest-message-util]` Print the inner errors of an `AggregateError` thrown inside a test ([#16316](https://github.com/jestjs/jest/pull/16316))
21+
- `[jest-message-util]` Indent nested `cause` and `AggregateError` sections of a test failure by one level per depth, so the nesting is legible instead of rendering flat ([#16316](https://github.com/jestjs/jest/pull/16316))
22+
- `[jest-message-util]` Color stack traces line by line so blank lines stay blank ([#16316](https://github.com/jestjs/jest/pull/16316))
1723
- `[jest-mock]` `mockResolvedValue` / `mockRejectedValue` now see all overload return types, so a Promise-returning overload survives even when a later overload returns a non-Promise (e.g. `pg.Client['end']`) ([#16237](https://github.com/jestjs/jest/pull/16237))
1824
- `[@jest-environment/jsdom-abstract]` Make `@types/jsdom` a peer dependency ([#16166](https://github.com/jestjs/jest/pull/16166))
1925
- `[jest-mock]` Remove the leftover own accessor descriptor when restoring a `spyOn` of an inherited getter or setter, so the instance keeps reflecting the prototype ([#16226](https://github.com/jestjs/jest/pull/16226))

‎e2e/__tests__/__snapshots__/failures.test.ts.snap‎

Lines changed: 99 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,82 @@ exports[`not throwing Error objects 6`] = `
281281
}"
282282
`;
283283
284+
exports[`works with AggregateError 1`] = `
285+
"FAIL __tests__/aggregateError.test.js
286+
✕ throws an AggregateError
287+
✕ rejects with an AggregateError from Promise.any
288+
289+
● throws an AggregateError
290+
291+
AggregateError:
292+
293+
18 |
294+
19 | it('throws an AggregateError', () => {
295+
> 20 | throw new AggregateError([new Error('inner A'), new Error('inner B')]);
296+
| ^
297+
21 | });
298+
22 |
299+
23 | it('rejects with an AggregateError from Promise.any', async () => {
300+
301+
at Object.<anonymous> (__tests__/aggregateError.test.js:20:9)
302+
303+
Errors contained in AggregateError:
304+
inner A
305+
306+
18 |
307+
19 | it('throws an AggregateError', () => {
308+
> 20 | throw new AggregateError([new Error('inner A'), new Error('inner B')]);
309+
| ^
310+
21 | });
311+
22 |
312+
23 | it('rejects with an AggregateError from Promise.any', async () => {
313+
314+
at Object.<anonymous> (__tests__/aggregateError.test.js:20:29)
315+
316+
inner B
317+
318+
18 |
319+
19 | it('throws an AggregateError', () => {
320+
> 20 | throw new AggregateError([new Error('inner A'), new Error('inner B')]);
321+
| ^
322+
21 | });
323+
22 |
324+
23 | it('rejects with an AggregateError from Promise.any', async () => {
325+
326+
at Object.<anonymous> (__tests__/aggregateError.test.js:20:51)
327+
328+
● rejects with an AggregateError from Promise.any
329+
330+
AggregateError: All promises were rejected
331+
332+
Errors contained in AggregateError:
333+
ECONNREFUSED primary
334+
335+
10 |
336+
11 | function connectToPrimary() {
337+
> 12 | return Promise.reject(new Error('ECONNREFUSED primary'));
338+
| ^
339+
13 | }
340+
14 |
341+
15 | function connectToReplica() {
342+
343+
at connectToPrimary (__tests__/aggregateError.test.js:12:25)
344+
at Object.connectToPrimary (__tests__/aggregateError.test.js:24:22)
345+
346+
ETIMEDOUT replica
347+
348+
14 |
349+
15 | function connectToReplica() {
350+
> 16 | return Promise.reject(new Error('ETIMEDOUT replica'));
351+
| ^
352+
17 | }
353+
18 |
354+
19 | it('throws an AggregateError', () => {
355+
356+
at connectToReplica (__tests__/aggregateError.test.js:16:25)
357+
at Object.connectToReplica (__tests__/aggregateError.test.js:24:42)"
358+
`;
359+
284360
exports[`works with assertions in separate files 1`] = `
285361
"FAIL __tests__/testMacro.test.js
286362
✕ use some imported macro to make assertion
@@ -428,19 +504,19 @@ exports[`works with error with cause 1`] = `
428504
at Object.f (__tests__/errorWithCause.test.js:32:3)
429505
430506
Cause:
431-
error during g
507+
error during g
432508
433-
19 |
434-
20 | function g() {
435-
> 21 | throw new Error('error during g');
436-
| ^
437-
22 | }
438-
23 | function f() {
439-
24 | try {
509+
19 |
510+
20 | function g() {
511+
> 21 | throw new Error('error during g');
512+
| ^
513+
22 | }
514+
23 | function f() {
515+
24 | try {
440516
441-
at g (__tests__/errorWithCause.test.js:21:9)
442-
at g (__tests__/errorWithCause.test.js:25:5)
443-
at Object.f (__tests__/errorWithCause.test.js:32:3)
517+
at g (__tests__/errorWithCause.test.js:21:9)
518+
at g (__tests__/errorWithCause.test.js:25:5)
519+
at Object.f (__tests__/errorWithCause.test.js:32:3)
444520
445521
● describe block › error with cause in describe/it
446522
@@ -459,19 +535,19 @@ exports[`works with error with cause 1`] = `
459535
at Object.f (__tests__/errorWithCause.test.js:37:5)
460536
461537
Cause:
462-
error during g
538+
error during g
463539
464-
19 |
465-
20 | function g() {
466-
> 21 | throw new Error('error during g');
467-
| ^
468-
22 | }
469-
23 | function f() {
470-
24 | try {
540+
19 |
541+
20 | function g() {
542+
> 21 | throw new Error('error during g');
543+
| ^
544+
22 | }
545+
23 | function f() {
546+
24 | try {
471547
472-
at g (__tests__/errorWithCause.test.js:21:9)
473-
at g (__tests__/errorWithCause.test.js:25:5)
474-
at Object.f (__tests__/errorWithCause.test.js:37:5)
548+
at g (__tests__/errorWithCause.test.js:21:9)
549+
at g (__tests__/errorWithCause.test.js:25:5)
550+
at Object.f (__tests__/errorWithCause.test.js:37:5)
475551
476552
● describe block › error with string cause in describe/it
477553
@@ -489,7 +565,7 @@ exports[`works with error with cause 1`] = `
489565
at Object.buildErrorWithCause (__tests__/errorWithCause.test.js:41:11)
490566
491567
Cause:
492-
here is the cause"
568+
here is the cause"
493569
`;
494570
495571
exports[`works with error with cause thrown outside tests 1`] = `

‎e2e/__tests__/__snapshots__/promiseAsyncHandling.test.ts.snap‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,91 @@ Ran all test suites matching unhandledRejectionTest.test.js.",
221221
}
222222
`;
223223
224+
exports[`reports the cause of an unhandled rejection 1`] = `
225+
Object {
226+
"rest": "FAIL __tests__/unhandledRejectionWithCause.test.js
227+
228+
229+
● Test suite failed to run
230+
231+
error during f
232+
233+
18 | g();
234+
19 | } catch (error) {
235+
> 20 | throw new Error('error during f', {cause: error});
236+
| ^
237+
21 | }
238+
22 | }
239+
23 |
240+
241+
at f (__tests__/unhandledRejectionWithCause.test.js:20:11)
242+
at Object.f (__tests__/unhandledRejectionWithCause.test.js:27:5)
243+
244+
Cause:
245+
error during g
246+
247+
11 |
248+
12 | function g() {
249+
> 13 | throw new Error('error during g');
250+
| ^
251+
14 | }
252+
15 |
253+
16 | function f() {
254+
255+
at g (__tests__/unhandledRejectionWithCause.test.js:13:9)
256+
at g (__tests__/unhandledRejectionWithCause.test.js:18:5)
257+
at Object.f (__tests__/unhandledRejectionWithCause.test.js:27:5)",
258+
"summary": "Test Suites: 1 failed, 1 total
259+
Tests: 1 passed, 1 total
260+
Snapshots: 0 total
261+
Time: <<REPLACED>>
262+
Ran all test suites matching unhandledRejectionWithCause.test.js.",
263+
}
264+
`;
265+
266+
exports[`reports the inner errors of an unhandled AggregateError rejection 1`] = `
267+
Object {
268+
"rest": "FAIL __tests__/unhandledRejectionAggregate.test.js
269+
270+
271+
● Test suite failed to run
272+
273+
AggregateError: All promises were rejected
274+
275+
Errors contained in AggregateError:
276+
ECONNREFUSED primary
277+
278+
11 |
279+
12 | function connectToPrimary() {
280+
> 13 | return Promise.reject(new Error('ECONNREFUSED primary'));
281+
| ^
282+
14 | }
283+
15 |
284+
16 | function connectToReplica() {
285+
286+
at connectToPrimary (__tests__/unhandledRejectionAggregate.test.js:13:25)
287+
at Object.connectToPrimary (__tests__/unhandledRejectionAggregate.test.js:21:16)
288+
289+
ETIMEDOUT replica
290+
291+
15 |
292+
16 | function connectToReplica() {
293+
> 17 | return Promise.reject(new Error('ETIMEDOUT replica'));
294+
| ^
295+
18 | }
296+
19 |
297+
20 | afterAll(async () => {
298+
299+
at connectToReplica (__tests__/unhandledRejectionAggregate.test.js:17:25)
300+
at Object.connectToReplica (__tests__/unhandledRejectionAggregate.test.js:21:36)",
301+
"summary": "Test Suites: 1 failed, 1 total
302+
Tests: 1 passed, 1 total
303+
Snapshots: 0 total
304+
Time: <<REPLACED>>
305+
Ran all test suites matching unhandledRejectionAggregate.test.js.",
306+
}
307+
`;
308+
224309
exports[`succeeds for async handled promise rejections 1`] = `
225310
Object {
226311
"rest": "PASS __tests__/rejectionHandled.test.js

‎e2e/__tests__/__snapshots__/requireMissingExt.test.ts.snap‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ exports[`shows a proper error from deep requires 1`] = `
1010
node_modules/discord.js/src/index.js
1111
__tests__/test.js
1212
13-
1413
However, Jest was able to find:
1514
'../package.json'
1615

‎e2e/__tests__/__snapshots__/resolveNoFileExtensions.test.ts.snap‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ exports[`show error message with matching files 1`] = `
2323
index.js
2424
__tests__/test.js
2525
26-
2726
However, Jest was able to find:
2827
'./some-json-file.json'
2928

‎e2e/__tests__/__snapshots__/testRetries.test.ts.snap‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,74 @@ PASS __tests__/logErrorsBeforeRetries.test.js
111111
✓ retryTimes set"
112112
`;
113113
114+
exports[`Test Retries logs the inner errors of an AggregateError before retry 1`] = `
115+
"LOGGING RETRY ERRORS retryTimes set
116+
RETRY 1
117+
118+
AggregateError: All promises were rejected
119+
120+
Errors contained in AggregateError:
121+
ECONNREFUSED primary
122+
123+
8 |
124+
9 | function connectToPrimary() {
125+
> 10 | return Promise.reject(new Error('ECONNREFUSED primary'));
126+
| ^
127+
11 | }
128+
12 |
129+
13 | function connectToReplica() {
130+
131+
at connectToPrimary (__tests__/logAggregateErrorsBeforeRetries.test.js:10:25)
132+
at Object.connectToPrimary (__tests__/logAggregateErrorsBeforeRetries.test.js:22:24)
133+
134+
ETIMEDOUT replica
135+
136+
12 |
137+
13 | function connectToReplica() {
138+
> 14 | return Promise.reject(new Error('ETIMEDOUT replica'));
139+
| ^
140+
15 | }
141+
16 |
142+
17 | let i = 0;
143+
144+
at connectToReplica (__tests__/logAggregateErrorsBeforeRetries.test.js:14:25)
145+
at Object.connectToReplica (__tests__/logAggregateErrorsBeforeRetries.test.js:22:44)
146+
147+
RETRY 2
148+
149+
AggregateError: All promises were rejected
150+
151+
Errors contained in AggregateError:
152+
ECONNREFUSED primary
153+
154+
8 |
155+
9 | function connectToPrimary() {
156+
> 10 | return Promise.reject(new Error('ECONNREFUSED primary'));
157+
| ^
158+
11 | }
159+
12 |
160+
13 | function connectToReplica() {
161+
162+
at connectToPrimary (__tests__/logAggregateErrorsBeforeRetries.test.js:10:25)
163+
at Object.connectToPrimary (__tests__/logAggregateErrorsBeforeRetries.test.js:22:24)
164+
165+
ETIMEDOUT replica
166+
167+
12 |
168+
13 | function connectToReplica() {
169+
> 14 | return Promise.reject(new Error('ETIMEDOUT replica'));
170+
| ^
171+
15 | }
172+
16 |
173+
17 | let i = 0;
174+
175+
at connectToReplica (__tests__/logAggregateErrorsBeforeRetries.test.js:14:25)
176+
at Object.connectToReplica (__tests__/logAggregateErrorsBeforeRetries.test.js:22:44)
177+
178+
PASS __tests__/logAggregateErrorsBeforeRetries.test.js
179+
✓ retryTimes set"
180+
`;
181+
114182
exports[`Test Retries wait before retry 1`] = `
115183
"LOGGING RETRY ERRORS retryTimes set
116184
RETRY 1

0 commit comments

Comments
 (0)