From 9cbc26bab656fa9e9952242b2d733a86c6a61d43 Mon Sep 17 00:00:00 2001 From: Nick McCurdy Date: Fri, 5 Jan 2018 06:42:01 -0500 Subject: [PATCH] Treat dumb terminals as noninteractive (#5237) * Treat dumb terminals as noninteractive * Add basic changelog entry --- CHANGELOG.md | 1 + .../src/__tests__/is_interactive.test.js | 15 +++++++++++++++ packages/jest-util/src/is_interative.js | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01945b2ba509..6d20f7030581 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;