You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem or a nice-to-have?? Please describe.
Sometimes I'm using Mocha to test something which can fail multiple ways. This is what AggregateError is designed for.
However, when an AggregateError is thrown in a Mocha test, nothing nice prints:
it("should work with AggregateErrors",()=>{consterr1=newError("1");consterr2=newError("2");constaggErr=newAggregateError([err1,err2],"2 errors");throwaggErr;});
gives
1) should work with AggregateErrors:
AggregateError: 2 errors
at Context.<anonymous> (x.test.js:4:18)
at process.processImmediate (node:internal/timers:478:21)
Describe the solution you'd like
It should probably print something for each error, as well as the AggregateError itself. Maybe
AggregateError: 2 errors
at Context.<anonymous> (x.test.js:4:18)
at process.processImmediate (node:internal/timers:478:21)
Error: 1
at Context.<anonymous> (x.test.js:2:16)
at process.processImmediate (node:internal/timers:478:21)
Error: 2
at Context.<anonymous> (x.test.js:3:16)
at process.processImmediate (node:internal/timers:478:21)
Describe alternatives you've considered
I tried making a fake AggregateError:
it("should work with fake AggregateErrors",()=>{consterr1=newError("1");consterr2=newError("2");constaggErr=newError(`2 errors:\n\n${err1.stack}\n\n${err2.stack}`);throwaggErr;});
This seems to confuse Mocha's stack trace defection code and result in printing the error twice:
1) should work with fake AggregateErrors:
2 errors:
Error: 1
at Context.<anonymous> (C:\Users\Domenic\Dropbox\Programming\WIP\jest-aggregateerror-test\x.test.js:2:16)
at callFn (C:\Users\Domenic\AppData\Local\npm-cache\_npx\508606763866ae01\node_modules\mocha\lib\runnable.js:366:21)
at Runnable.run (C:\Users\Domenic\AppData\Local\npm-cache\_npx\508606763866ae01\node_modules\mocha\lib\runnable.js:354:5)
at Runner.runTest (C:\Users\Domenic\AppData\Local\npm-cache\_npx\508606763866ae01\node_modules\mocha\lib\runner.js:666:10)
at C:\Users\Domenic\AppData\Local\npm-cache\_npx\508606763866ae01\node_modules\mocha\lib\runner.js:789:12
at next (C:\Users\Domenic\AppData\Local\npm-cache\_npx\508606763866ae01\node_modules\mocha\lib\runner.js:581:14)
at C:\Users\Domenic\AppData\Local\npm-cache\_npx\508606763866ae01\node_modules\mocha\lib\runner.js:591:7
at next (C:\Users\Domenic\AppData\Local\npm-cache\_npx\508606763866ae01\node_modules\mocha\lib\runner.js:474:14)
at Immediate._onImmediate (C:\Users\Domenic\AppData\Local\npm-cache\_npx\508606763866ae01\node_modules\mocha\lib\runner.js:559:5)
at process.processImmediate (node:internal/timers:478:21)
Error: 2
at Context.<anonymous> (C:\Users\Domenic\Dropbox\Programming\WIP\jest-aggregateerror-test\x.test.js:4:16)
at callFn (C:\Users\Domenic\AppData\Local\npm-cache\_npx\508606763866ae01\node_modules\mocha\lib\runnable.js:366:21)
at Runnable.run (C:\Users\Domenic\AppData\Local\npm-cache\_npx\508606763866ae01\node_modules\mocha\lib\runnable.js:354:5)
at Runner.runTest (C:\Users\Domenic\AppData\Local\npm-cache\_npx\508606763866ae01\node_modules\mocha\lib\runner.js:666:10)
at C:\Users\Domenic\AppData\Local\npm-cache\_npx\508606763866ae01\node_modules\mocha\lib\runner.js:789:12
at next (C:\Users\Domenic\AppData\Local\npm-cache\_npx\508606763866ae01\node_modules\mocha\lib\runner.js:581:14)
at C:\Users\Domenic\AppData\Local\npm-cache\_npx\508606763866ae01\node_modules\mocha\lib\runner.js:591:7
at next (C:\Users\Domenic\AppData\Local\npm-cache\_npx\508606763866ae01\node_modules\mocha\lib\runner.js:474:14)
at Immediate._onImmediate (C:\Users\Domenic\AppData\Local\npm-cache\_npx\508606763866ae01\node_modules\mocha\lib\runner.js:559:5)
at process.processImmediate (node:internal/timers:478:21)
Error: 2 errors:
Error: 1
at Context.<anonymous> (x.test.js:2:16)
at process.processImmediate (node:internal/timers:478:21)
Error: 2
at Context.<anonymous> (x.test.js:4:16)
at process.processImmediate (node:internal/timers:478:21)
at Context.<anonymous> (x.test.js:6:18)
at process.processImmediate (node:internal/timers:478:21)
This is my current best solution but it's pretty noisy to get duplicate errors.
The text was updated successfully, but these errors were encountered:
JoshuaKGoldberg
changed the title
Support printing AggregateErrors sensibly
🚀 Feature: Support printing AggregateErrors
Dec 27, 2023
JoshuaKGoldberg
changed the title
🚀 Feature: Support printing AggregateErrors
🚀 Feature: Support printing each error within AggregateErrors
Dec 27, 2023
Is your feature request related to a problem or a nice-to-have?? Please describe.
Sometimes I'm using Mocha to test something which can fail multiple ways. This is what
AggregateError
is designed for.However, when an
AggregateError
is thrown in a Mocha test, nothing nice prints:gives
Describe the solution you'd like
It should probably print something for each error, as well as the AggregateError itself. Maybe
Describe alternatives you've considered
I tried making a fake
AggregateError
:This seems to confuse Mocha's stack trace defection code and result in printing the error twice:
This is my current best solution but it's pretty noisy to get duplicate errors.
The text was updated successfully, but these errors were encountered: