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(jest-message-util): improve detection of error causes #13912

Merged
merged 2 commits into from Feb 15, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/jest-message-util/src/index.ts
Expand Up @@ -152,7 +152,15 @@ export const formatExecError = (
const prefix = '\n\nCause:\n';
if (typeof error.cause === 'string' || typeof error.cause === 'number') {
cause += `${prefix}${error.cause}`;
} else if (types.isNativeError(error.cause)) {
} else if (
types.isNativeError(error.cause) ||
error.cause instanceof Error
) {
/* `isNativeError` is used, because the error might come from another realm.
`instanceof Error` is used because `isNativeError` does return `false` for some
things that are `instanceof Error` like the errors provided in
[verror](https://www.npmjs.com/package/verror) or [axios](https://axios-http.com).
*/
const formatted = formatExecError(
error.cause,
config,
Expand Down