Add option for cleaner error reporting in fc.assert #6035
-
🚀 Feature RequestWhen using fc.assert in modern test runners like Vitest or Jest, the error output tends to be very verbose — with stack traces originating deep from inside fast-check internals. We'd love a cleaner, user-focused error like: ❌ Property failed after 3 tests. Failing inputs: [0, 100001] Allowing a custom errorFormatter Or a suppressStackTrace option Or a lightweight fc.assertClean alternative This would help a lot with DX and improve the readability of PBT failures. MotivationCleaner tests output without stack traces ExampleCurrent output is way too dirty -
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Thanks for having reported this issue. If I'm not wrong this is the exact purpose of the parameters called More details: here. Hope it solves your issue 👍 |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for kindly pointing that out. Works like a charm! |
Beta Was this translation helpful? Give feedback.
-
Hi Nicolas! I met another obstacle with this attitude. With custom reporter I get clean output locally, but Isn't there a way to have both - exit code 1 and clean output? do I have to analyze output for keywords to know test failed, or there is a better way? Sorry for disturbance with another probably silly question! Thank you!
|
Beta Was this translation helpful? Give feedback.
-
You normally have to throw in case it's an error case as we do within our default reporters: /** @internal */
function throwIfFailed<Ts>(out: RunDetails<Ts>): void {
if (!out.failed) return;
throw buildError<Ts>(defaultReportMessage(out), out);
}
/** @internal */
async function asyncThrowIfFailed<Ts>(out: RunDetails<Ts>): Promise<void> {
if (!out.failed) return;
throw buildError<Ts>(await asyncDefaultReportMessage(out), out);
} This is the default code for reporters. |
Beta Was this translation helpful? Give feedback.
-
Thank you! I finished with clearing stack before throwing. |
Beta Was this translation helpful? Give feedback.
Thanks for having reported this issue. If I'm not wrong this is the exact purpose of the parameters called
reporter
andasyncReporter
that you can provide to theassert
function provided by fast-check. If you want your reporter to be used everywhere (ie for all calls toassert
) you can configure it globally by passing it toconfigureGlobal
.More details: here.
Hope it solves your issue 👍