Skip to content

Commit

Permalink
Fix runGlobalHook error when message is unwritable (#14113)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-szabo97 committed Jul 27, 2023
1 parent 23cc165 commit e7d991c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixes

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

Expand Down
9 changes: 8 additions & 1 deletion packages/jest-core/src/runGlobalHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e7d991c

Please sign in to comment.