Skip to content

Commit

Permalink
ensure FORCE_COLOR maxes out at a value of three
Browse files Browse the repository at this point in the history
  • Loading branch information
deecewan committed Oct 14, 2018
1 parent bdf2cb2 commit 3f6b55f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -23,7 +23,7 @@ if ('FORCE_COLOR' in env) {
} else {
forceColor = env.FORCE_COLOR.length === 0 ?
1 :
parseInt(env.FORCE_COLOR, 10);
Math.min(parseInt(env.FORCE_COLOR, 10), 3);
}
}

Expand Down
16 changes: 16 additions & 0 deletions test.js
Expand Up @@ -320,6 +320,11 @@ test('return level 2 when FORCE_COLOR is set when not TTY in xterm256', t => {

test('supports setting a color value using FORCE_COLOR', t => {
let result;
process.env.FORCE_COLOR = '1';
result = importFresh('.');
t.truthy(result.stdout);
t.is(result.stdout.level, 1);

process.env.FORCE_COLOR = '2';
result = importFresh('.');
t.truthy(result.stdout);
Expand All @@ -329,6 +334,17 @@ test('supports setting a color value using FORCE_COLOR', t => {
result = importFresh('.');
t.truthy(result.stdout);
t.is(result.stdout.level, 3);

process.env.FORCE_COLOR = '0';
result = importFresh('.');
t.false(result.stdout);
});

test('FORCE_COLOR maxes out at a value of 3', t => {
process.env.FORCE_COLOR = '4';
const result = importFresh('.');
t.truthy(result.stdout);
t.is(result.stdout.level, 3);
});

test('FORCE_COLOR works when set via command line (all values are strings)', t => {
Expand Down

0 comments on commit 3f6b55f

Please sign in to comment.