Skip to content

Commit e7d991c

Browse files
Fix runGlobalHook error when message is unwritable (#14113)
1 parent 23cc165 commit e7d991c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Fixes
66

77
- `[jest-circus]` Fix snapshot matchers in concurrent tests when nr of tests exceeds `maxConcurrency` ([#14335](https://github.com/jestjs/jest/pull/14335))
8+
- `[@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 ([#14113](https://github.com/jestjs/jest/pull/14113))
89
- `[jest-snapshot]` Move `@types/prettier` from `dependencies` to `devDependencies` ([#14328](https://github.com/jestjs/jest/pull/14328))
910
- `[jest-reporters]` Add "skipped" and "todo" symbols to Github Actions Reporter ([#14309](https://github.com/jestjs/jest/pull/14309))
1011

packages/jest-core/src/runGlobalHook.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ export default async function runGlobalHook({
5959
},
6060
);
6161
} catch (error) {
62-
if (util.types.isNativeError(error)) {
62+
if (
63+
util.types.isNativeError(error) &&
64+
(Object.getOwnPropertyDescriptor(error, 'message')?.writable ||
65+
Object.getOwnPropertyDescriptor(
66+
Object.getPrototypeOf(error),
67+
'message',
68+
)?.writable)
69+
) {
6370
error.message = `Jest: Got error running ${moduleName} - ${modulePath}, reason: ${error.message}`;
6471

6572
throw error;

0 commit comments

Comments
 (0)