diff --git a/index.js b/index.js index 4ce0a2d..575a8fe 100644 --- a/index.js +++ b/index.js @@ -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) { @@ -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; diff --git a/test.js b/test.js index dfcb2f1..7987aa7 100644 --- a/test.js +++ b/test.js @@ -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');