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

Give TERM=dumb higher priority #90

Merged
merged 2 commits into from Dec 21, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions index.js
Expand Up @@ -53,6 +53,10 @@ function supportsColor(stream) {

const min = forceColor ? 1 : 0;

if (env.TERM === 'dumb') {
return min;
}

if (process.platform === 'win32') {
// Node.js 7.5.0 is the first version of Node.js to include a patch to
// libuv that enables 256 color output on Windows. Anything earlier and it
Expand Down Expand Up @@ -112,10 +116,6 @@ function supportsColor(stream) {
return 1;
}

if (env.TERM === 'dumb') {
return min;
}

return min;
}

Expand Down
34 changes: 34 additions & 0 deletions test.js
Expand Up @@ -317,3 +317,37 @@ test('return level 2 when FORCE_COLOR is set when not TTY in xterm256', t => {
t.truthy(result.stdout);
t.is(result.stdout.level, 2);
});

test('return false when `TERM` is set to dumb', t => {
process.env.TERM = 'dumb';
const result = importFresh('.');
t.false(result.stdout);
});

test('return false when `TERM` is set to dumb when `TERM_PROGRAM` is set', t => {
process.env.TERM = 'dumb';
process.env.TERM_PROGRAM = 'Apple_Terminal';
const result = importFresh('.');
t.false(result.stdout);
});

test('return false when `TERM` is set to dumb when run on Windows', t => {
Object.defineProperty(process, 'platform', {
value: 'win32'
});
Object.defineProperty(process.versions, 'node', {
value: '10.13.0'
});
os.release = () => '10.0.14931';
process.env.TERM = 'dumb';
const result = importFresh('.');
t.false(result.stdout);
});

test('return level 1 when `TERM` is set to dumb when `FORCE_COLOR` is set', t => {
process.env.FORCE_COLOR = '1';
process.env.TERM = 'dumb';
const result = importFresh('.');
t.truthy(result.stdout);
t.is(result.stdout.level, 1);
});