From fe4ac691194c42fed6b6c18d460c210a41b1cc32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Szab=C3=B3?= Date: Fri, 28 Apr 2023 08:54:56 +0200 Subject: [PATCH 1/2] Fix runGlobalHook error when message is unwritable --- packages/jest-core/src/runGlobalHook.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/jest-core/src/runGlobalHook.ts b/packages/jest-core/src/runGlobalHook.ts index 53dced982bc2..4f8a995ca335 100644 --- a/packages/jest-core/src/runGlobalHook.ts +++ b/packages/jest-core/src/runGlobalHook.ts @@ -59,7 +59,14 @@ export default async function runGlobalHook({ }, ); } catch (error) { - if (util.types.isNativeError(error)) { + if ( + util.types.isNativeError(error) && + (Object.getOwnPropertyDescriptor(error, 'message')?.writable || + Object.getOwnPropertyDescriptor( + Object.getPrototypeOf(error), + 'message', + )?.writable) + ) { error.message = `Jest: Got error running ${moduleName} - ${modulePath}, reason: ${error.message}`; throw error; From 0ec6646e39c7ed8d3732be09651793dcafef375c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Szab=C3=B3?= Date: Fri, 28 Apr 2023 09:00:01 +0200 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25a5ac6591ca..3b9a95e2c193 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - `[jest-runtime]` Bind `jest.isolateModulesAsync` to `this` ([#14083](https://github.com/facebook/jest/pull/14083)) - `[jest-snapshot]` Fix a potential bug when not using prettier and improve performance ([#14036](https://github.com/facebook/jest/pull/14036)) - `[@jest/transform]` Do not instrument `.json` modules ([#14048](https://github.com/facebook/jest/pull/14048)) +- `[jest-core]` When running global setup and teardown, do not try to change the `message` property of the thrown error object when the `message` property is unwritable ### Chore & Maintenance