diff --git a/CHANGELOG.md b/CHANGELOG.md index ee9305949add..fb26aee44cc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Fixes +* `[jest-cli]` Treat dumb terminals as noninteractive ([#5237](https://github.com/facebook/jest/pull/5237)) * `[jest-cli]` `jest --onlyChanged --changedFilesWithAncestor` now also works with git. ([#5189](https://github.com/facebook/jest/pull/5189)) * `[jest-config]` fix unexpected condition to avoid infinite recursion in diff --git a/packages/jest-util/src/__tests__/is_interactive.test.js b/packages/jest-util/src/__tests__/is_interactive.test.js index 7cf2a9a8b9a7..4ebad99490ba 100644 --- a/packages/jest-util/src/__tests__/is_interactive.test.js +++ b/packages/jest-util/src/__tests__/is_interactive.test.js @@ -1,17 +1,21 @@ let oldIsTTY; +let oldTERM; beforeEach(() => { oldIsTTY = process.stdout.isTTY; + oldTERM = process.env.TERM; }); afterEach(() => { process.stdout.isTTY = oldIsTTY; + process.env.TERM = oldTERM; jest.resetModules(); }); it('Returns true when running on interactive environment', () => { jest.doMock('is-ci', () => false); process.stdout.isTTY = true; + process.env.TERM = 'xterm-256color'; const isInteractive = require('../is_interative').default; expect(isInteractive).toBe(true); @@ -24,6 +28,7 @@ it('Returns false when running on a non-interactive environment', () => { // Test with is-ci being true and isTTY false jest.doMock('is-ci', () => true); process.stdout.isTTY = false; + process.env.TERM = 'xterm-256color'; isInteractive = require('../is_interative').default; expect(isInteractive).toBe(expectedResult); @@ -31,6 +36,7 @@ it('Returns false when running on a non-interactive environment', () => { jest.resetModules(); jest.doMock('is-ci', () => false); process.stdout.isTTY = false; + process.env.TERM = 'xterm-256color'; isInteractive = require('../is_interative').default; expect(isInteractive).toBe(expectedResult); @@ -38,6 +44,15 @@ it('Returns false when running on a non-interactive environment', () => { jest.resetModules(); jest.doMock('is-ci', () => true); process.stdout.isTTY = true; + process.env.TERM = 'xterm-256color'; + isInteractive = require('../is_interative').default; + expect(isInteractive).toBe(expectedResult); + + // Test with dumb terminal + jest.resetModules(); + jest.doMock('is-ci', () => false); + process.stdout.isTTY = false; + process.env.TERM = 'dumb'; isInteractive = require('../is_interative').default; expect(isInteractive).toBe(expectedResult); }); diff --git a/packages/jest-util/src/is_interative.js b/packages/jest-util/src/is_interative.js index 0ef48457b22c..0a81e738ba2e 100644 --- a/packages/jest-util/src/is_interative.js +++ b/packages/jest-util/src/is_interative.js @@ -1,3 +1,3 @@ import isCI from 'is-ci'; -export default process.stdout.isTTY && !isCI; +export default process.stdout.isTTY && process.env.TERM !== 'dumb' && !isCI;