Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat dumb terminals as noninteractive #5237

Merged
merged 2 commits into from
Jan 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions packages/jest-util/src/__tests__/is_interactive.test.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -24,20 +28,31 @@ 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);

// Test with is-ci being false and isTTY false
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);

// Test with is-ci being true and isTTY true
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);
});
2 changes: 1 addition & 1 deletion packages/jest-util/src/is_interative.js
Original file line number Diff line number Diff line change
@@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like there should exist some module which has this logic already

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same feeling, but I couldn't find one that specifically checks for a dumb terminal without doing other stuff. For example supports-color takes into account if a terminal is dumb but it's coupled with color related features that we don't want to check in this case.