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 e6b4bbc
Show file tree
Hide file tree
Showing 2 changed files with 12 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
11 changes: 11 additions & 0 deletions test.js
Expand Up @@ -329,6 +329,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 e6b4bbc

Please sign in to comment.