Skip to content

Commit

Permalink
Fix: CLI flags and FORCE_COLOR should precede other color support che…
Browse files Browse the repository at this point in the history
…cks (#154)
  • Loading branch information
m15a committed Feb 13, 2024
1 parent d4f413e commit edc5d7d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Expand Up @@ -65,8 +65,8 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {

const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;

if (forceColor === 0) {
return 0;
if (forceColor !== undefined) {
return forceColor;
}

if (sniffFlags) {
Expand All @@ -91,7 +91,7 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
return 0;
}

const min = forceColor || 0;
const min = 0;

if (env.TERM === 'dumb') {
return min;
Expand Down
16 changes: 16 additions & 0 deletions test.js
Expand Up @@ -46,6 +46,22 @@ test('return true if `FORCE_COLOR` is in env, but honor 256 #2', t => {
t.is(result.stdout.level, 2);
});

test('CLI color flags precede other color support checks', t => {
process.env.COLORTERM = 'truecolor';
process.argv = ['--color=256'];
const result = importFresh('./index.js');
t.truthy(result.stdout);
t.is(result.stdout.level, 2)
});

test('`FORCE_COLOR` environment variable precedes other color support checks', t => {
process.env.COLORTERM = 'truecolor';
process.env.FORCE_COLOR = '2';
const result = importFresh('./index.js');
t.truthy(result.stdout);
t.is(result.stdout.level, 2)
});

test('return false if `FORCE_COLOR` is in env and is 0', t => {
process.env.FORCE_COLOR = '0';
const result = importFresh('./index.js');
Expand Down

0 comments on commit edc5d7d

Please sign in to comment.