From f38c05cb932dd7aba7a2aee2b3d4023700307c72 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 20 Sep 2023 13:26:38 +0200 Subject: [PATCH] fix(jest-util): make sure `isInteractive` works in a browser (#14552) --- CHANGELOG.md | 1 + packages/jest-util/src/isInteractive.ts | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15c7ced02dc3..0d8bf5a32883 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - `[babel-plugin-jest-hoist]` Use `denylist` instead of the deprecated `blacklist` for Babel 8 support ([#14109](https://github.com/jestjs/jest/pull/14109)) - `[@jest/expect-utils]` Fix comparison of `DataView` ([#14408](https://github.com/jestjs/jest/pull/14408)) - `[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)) - `[pretty-format]` [**BREAKING**] Print `ArrayBuffer` and `DataView` correctly ([#14290](https://github.com/facebook/jest/pull/14290)) ### Performance 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;