From eed1412015e510c573dd1e340c1766acb1b33922 Mon Sep 17 00:00:00 2001 From: Tereza Tomcova Date: Fri, 13 Oct 2023 21:17:22 +0200 Subject: [PATCH] fix: log unhandled error even if its stack is empty --- CHANGELOG.md | 1 + packages/jest-reporters/src/CoverageWorker.ts | 6 +++++- packages/jest-runner/src/testWorker.ts | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e24c0b8cb2a..73dc228b0e1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ - `[jest-cli]` When specifying paths on the command line, only match against the relative paths of the test files ([#12519](https://github.com/facebook/jest/pull/12519)) - [**BREAKING**] Changes `testPathPattern` configuration option to `testPathPatterns`, which now takes a list of patterns instead of the regex. - [**BREAKING**] `--testPathPattern` is now `--testPathPatterns` +- `[jest-reporters, jest-runner]` Unhandled errors without stack get correctly logged to console ([#14619](https://github.com/facebook/jest/pull/14619)) ### Performance diff --git a/packages/jest-reporters/src/CoverageWorker.ts b/packages/jest-reporters/src/CoverageWorker.ts index 0d6349bc6f71..37adb50cc4e8 100644 --- a/packages/jest-reporters/src/CoverageWorker.ts +++ b/packages/jest-reporters/src/CoverageWorker.ts @@ -33,7 +33,11 @@ export type CoverageWorkerData = { // Make sure uncaught errors are logged before we exit. process.on('uncaughtException', err => { - console.error(err.stack); + if (err.stack) { + console.error(err.stack); + } else { + console.error(err); + } exit(1); }); diff --git a/packages/jest-runner/src/testWorker.ts b/packages/jest-runner/src/testWorker.ts index 4d1ee811f8e5..8864cf0616d9 100644 --- a/packages/jest-runner/src/testWorker.ts +++ b/packages/jest-runner/src/testWorker.ts @@ -35,7 +35,11 @@ type WorkerData = { // Make sure uncaught errors are logged before we exit. process.on('uncaughtException', err => { - console.error(err.stack); + if (err.stack) { + console.error(err.stack); + } else { + console.error(err); + } exit(1); });