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
{{ message }}
Repository navigation
.cause of errors innode:test test cases not available to custom reporter #48900
import{test}from"node:test";test("causes",()=>{consterr1=newError("Inner");thrownewError("Outer",{cause: err1});});And:
```js
export default async function* customReporter(source) {
for await (const event of source) {
if (event.type === "test:fail") {
let err = event.data.details.error;
if (err.code === "ERR_TEST_FAILURE") {
err = err.cause;
}
yield "Outer error: " + err.message + "\n";
yield "Inner error: " + err.cause?.message + "\n";}}}
Will log:
Outer error: Outer
Inner error: undefined
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
I expected the .cause (and other properties of the Error) to be available to the reporter and thus for the output of the above reproduction to be:
Outer error: Outer
Inner error: Inner
What do you see instead?
Neither the .cause (or other properties I add to the Error) is available to the reporter and the output of the above thus is:
Outer error: Outer
Inner error: undefined
I do see eg the expected property of an AssertionError from Chai or node:assert carry through though, not sure why those are carried through but other properties are not.
Additional information
Getting the full cause chain can be crucial in understanding an unexpected error.
An error chain that's Could not create DB > Unable to connect to DB > <CONNECTION_ERROR> needs all the parts to make sense, but right now node:test reporters are only able to show the topmost error, Could not create DB.
@MoLow Does indeed look fixed! That's great 👍 Now onto styling them in my reporter
Thanks for the compliments! #47164 looks nice indeed, I will update my README. I guess diffing of AssertionError:s is not yet supported in core at least?
Activity
MoLow commentedon Jul 24, 2023
this seems to work for me on version
18.17.0(probably fixed by #47867), can you please check?MoLow commentedon Jul 24, 2023
also, nice work on https://github.com/voxpelli/node-test-pretty-reporter 🎉
note some of the things there are implemented inside core, e.g #47164
voxpelli commentedon Jul 24, 2023
@MoLow Does indeed look fixed! That's great 👍 Now onto styling them in my reporter
Thanks for the compliments! #47164 looks nice indeed, I will update my README. I guess diffing of AssertionError:s is not yet supported in core at least?
voxpelli commentedon Jul 24, 2023
In
18.17.0this started to fail though: https://github.com/voxpelli/node-test-pretty-reporter/blob/cee16190119a1260d96a57d65fb8564a131980b8/lib/errors.js#L10For some reason there is no longer a
codeproperty on thedata.details.errorthat I'm getting, any idea @MoLow?MoLow commentedon Jul 24, 2023
I am not sure what you mean?
AssertErrorimplements aninspect.customproperty to diff the assertionMoLow commentedon Jul 24, 2023
well the example used in this issue does seem to work:
voxpelli commentedon Jul 25, 2023
Support for the more standard way of doing it, the
.expected+.actualproperties on the error: https://mochajs.org/#diffs