From b01a979fc74507e29dbc3e2c607f474d20ac42c9 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 20 Sep 2023 09:13:37 +0200 Subject: [PATCH 1/2] fix(jest-util): make sure `isInteractive` works in a browser --- packages/jest-util/src/isInteractive.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/jest-util/src/isInteractive.ts b/packages/jest-util/src/isInteractive.ts index 0cdfbb2a9f15..67023b0a2146 100644 --- a/packages/jest-util/src/isInteractive.ts +++ b/packages/jest-util/src/isInteractive.ts @@ -7,4 +7,23 @@ import {isCI} from 'ci-info'; -export default !!process.stdout.isTTY && process.env.TERM !== 'dumb' && !isCI; +function checkIsInteractive(): boolean { + if (isCI) { + return false; + } + + // this can happen in a browser with polyfills: https://github.com/defunctzombie/node-process/issues/41 + if (process.stdout == null) { + return false; + } + + if (process.stdout.isTTY) { + return process.env.TERM !== 'dumb'; + } + + return false; +} + +const isInteractive = checkIsInteractive(); + +export default isInteractive; From c943a73db8dca54a8eb589e4496f3ee59182c248 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 20 Sep 2023 09:15:44 +0200 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17e27fabd77b..270c989b9d3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ ### Fixes - `[jest-leak-detector]` Make leak-detector more aggressive when running GC ([#14526](https://github.com/jestjs/jest/pull/14526)) +- `[jest-util]` Make sure `isInteractive` works in a browser ([#14552](https://github.com/jestjs/jest/pull/14552)) ### Performance