From 61670c55ea0672c094fa819730c01468893c2da3 Mon Sep 17 00:00:00 2001 From: Julian Dax Date: Tue, 14 Feb 2023 19:58:11 +0100 Subject: [PATCH 1/2] feat(jest-message-util): improve detection of error causes --- packages/jest-message-util/src/index.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/jest-message-util/src/index.ts b/packages/jest-message-util/src/index.ts index d4e9059460ee..bf03d9d547d4 100644 --- a/packages/jest-message-util/src/index.ts +++ b/packages/jest-message-util/src/index.ts @@ -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, From 0ec5702f59dcd56de793409d61856cefdefe2ba5 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 15 Feb 2023 10:48:55 +0100 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce86f3d161fa..56c7dd2df25e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### Features -- `[jest-message-util]` Add support for [error causes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause) +- `[jest-message-util]` Add support for [error causes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause) ([#13868](https://github.com/facebook/jest/pull/13868) & [#13912](https://github.com/facebook/jest/pull/13912)) ### Fixes