You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Two test cases are failing, present at line 44 and line 52 in test.js (although 4 test cases are failing but I'm considering 2 since I was able to fix only 2, solution is provided below):
test('return true if `FORCE_COLOR` is in env, but honor 256',asynct=>{process.argv=['--color=256'];process.env.FORCE_COLOR='true';constresult=awaitimportMain();t.truthy(result.stdout);t.is(result.stdout.level,2);});
test('return true if `FORCE_COLOR` is in env, but honor 256 #2',asynct=>{process.argv=['--color=256'];process.env.FORCE_COLOR='1';constresult=awaitimportMain();t.truthy(result.stdout);t.is(result.stdout.level,2);});
Failed Tests
>[email protected]test> xo && ava && tsd
index.js:72:1
⚠ 72:1 Function _supportsColor has a complexity of 36. Maximum allowed is 20. complexity
1 warning
✔ returntrueif`FORCE_COLOR` is in env
✘ [fail]: returntrueif`FORCE_COLOR` is in env, but honor 256
✘ [fail]: returntrueif`FORCE_COLOR` is in env, but honor 256 #2
✔ CLI color flags precede other color support checks
✔ `FORCE_COLOR` environment variable precedes other color support checks
✔ returnfalseif`FORCE_COLOR` is in env and is 0
✔ do not cache `FORCE_COLOR`
✔ returnfalseif not TTY
✔ returnfalseif --no-color flag is used
✔ returnfalseif --no-colors flag is used
✔ returntrueif --color flag is used
✔ returntrueif --colors flag is used
✔ returntrueif`COLORTERM` is in env
✔ support `--color=true` flag
✔ support `--color=always` flag
✔ support `--color=false` flag
✔ support `--color=256` flag
✔ level should be 2 if`--color=256` flag is used
✔ support `--color=16m` flag
✔ support `--color=full` flag
✔ support `--color=truecolor` flag
✔ level should be 3 if`--color=16m` flag is used
✔ ignore post-terminator flags
✔ allow tests of the properties on false
✔ returnfalseif`CI` is in env
✔ returntrueif`TRAVIS` is in env
✔ returntrueif`CIRCLECI` is in env
✔ returntrueif`APPVEYOR` is in env
✔ returntrueif`GITLAB_CI` is in env
✔ returntrueif`BUILDKITE` is in env
✔ returntrueif`DRONE` is in env
✔ return level 3 if`GITEA_ACTIONS` is in env
✔ returntrueif Codeship is in env
✔ returnfalseif`TEAMCITY_VERSION` is in env and is < 9.1
✔ return level 1 if`TEAMCITY_VERSION` is in env and is >= 9.1
✔ support rxvt
✔ prefer level 2/xterm over COLORTERM
✔ support screen-256color
✔ support putty-256color
✔ level should be 3 when using iTerm 3.0
✔ level should be 2 when using iTerm 2.9
✔ return level 1 if on Windows earlier than 10 build 10586
✔ return level 2 if on Windows 10 build 10586 or later
✔ return level 3 if on Windows 10 build 14931 or later
✘ [fail]: return level 2 when FORCE_COLOR is set when not TTY in xterm256
✔ supports setting a color level using FORCE_COLOR
✔ FORCE_COLOR maxes out at a value of 3
✘ [fail]: FORCE_COLOR works when set via command line (all values are strings)
✔ returnfalse when `TERM` is set to dumb
✔ returnfalse when `TERM` is set to dumb when `TERM_PROGRAM` is set
✔ returnfalse when `TERM` is set to dumb when run on Windows
✔ return level 1 when `TERM` is set to dumb when `FORCE_COLOR` is set
✔ ignore flags when sniffFlags=false
─
returntrueif`FORCE_COLOR` is in env, but honor 256
test.js:44
43: t.truthy(result.stdout);
44: t.is(result.stdout.level, 2);
45: });
Difference (- actual, + expected):
- 1
+ 2
› file://test.js:44:4
returntrueif`FORCE_COLOR` is in env, but honor 256 #2
test.js:52
51: t.truthy(result.stdout);
52: t.is(result.stdout.level, 2);
53: });
Difference (- actual, + expected):
- 1
+ 2
› file://test.js:52:4
return level 2 when FORCE_COLOR is set when not TTY in xterm256
test.js:354
353: t.truthy(result.stdout);
354: t.is(result.stdout.level, 2);
355: });
Difference (- actual, + expected):
- 1
+ 2
› file://test.js:354:4
FORCE_COLOR works when set via command line (all values are strings)
test.js:398
397: t.truthy(result.stdout);
398: t.is(result.stdout.level, 2);
399:
Difference (- actual, + expected):
- 1
+ 2
› file://test.js:398:4
─
4 tests failed
Solution
In test.js, process.argv is set as --color=256 and process.env.FORCE_COLOR is set to 'true' and 1.
However, in index.js, at line 80, we have an if statement that checks value of forceColor and returns it,
if(forceColor!==undefined){returnforceColor;}
Then we have another if condition at line 84 that checks for color=256 flag,
failed test cases reduced to two after the solution is applied
>[email protected]test> xo && ava && tsd
index.js:72:1
⚠ 72:1 Function _supportsColor has a complexity of 36. Maximum allowed is 20. complexity
1 warning
✔ returntrueif`FORCE_COLOR` is in env
✔ returntrueif`FORCE_COLOR` is in env, but honor 256
✔ returntrueif`FORCE_COLOR` is in env, but honor 256 #2
✔ CLI color flags precede other color support checks
✔ `FORCE_COLOR` environment variable precedes other color support checks
✔ returnfalseif`FORCE_COLOR` is in env and is 0
✔ do not cache `FORCE_COLOR`
✔ returnfalseif not TTY
✔ returnfalseif --no-color flag is used
✔ returnfalseif --no-colors flag is used
✔ returntrueif --color flag is used
✔ returntrueif --colors flag is used
✔ returntrueif`COLORTERM` is in env
✔ support `--color=true` flag
✔ support `--color=always` flag
✔ support `--color=false` flag
✔ support `--color=256` flag
✔ level should be 2 if`--color=256` flag is used
✔ support `--color=16m` flag
✔ support `--color=full` flag
✔ support `--color=truecolor` flag
✔ level should be 3 if`--color=16m` flag is used
✔ ignore post-terminator flags
✔ allow tests of the properties on false
✔ returnfalseif`CI` is in env
✔ returntrueif`TRAVIS` is in env
✔ returntrueif`CIRCLECI` is in env
✔ returntrueif`APPVEYOR` is in env
✔ returntrueif`GITLAB_CI` is in env
✔ returntrueif`BUILDKITE` is in env
✔ returntrueif`DRONE` is in env
✔ return level 3 if`GITEA_ACTIONS` is in env
✔ returntrueif Codeship is in env
✔ returnfalseif`TEAMCITY_VERSION` is in env and is < 9.1
✔ return level 1 if`TEAMCITY_VERSION` is in env and is >= 9.1
✔ support rxvt
✔ prefer level 2/xterm over COLORTERM
✔ support screen-256color
✔ support putty-256color
✔ level should be 3 when using iTerm 3.0
✔ level should be 2 when using iTerm 2.9
✔ return level 1 if on Windows earlier than 10 build 10586
✔ return level 2 if on Windows 10 build 10586 or later
✔ return level 3 if on Windows 10 build 14931 or later
✘ [fail]: return level 2 when FORCE_COLOR is set when not TTY in xterm256
✔ supports setting a color level using FORCE_COLOR
✔ FORCE_COLOR maxes out at a value of 3
✘ [fail]: FORCE_COLOR works when set via command line (all values are strings)
✔ returnfalse when `TERM` is set to dumb
✔ returnfalse when `TERM` is set to dumb when `TERM_PROGRAM` is set
✔ returnfalse when `TERM` is set to dumb when run on Windows
✔ return level 1 when `TERM` is set to dumb when `FORCE_COLOR` is set
✔ ignore flags when sniffFlags=false
─
return level 2 when FORCE_COLOR is set when not TTY in xterm256
test.js:354
353: t.truthy(result.stdout);
354: t.is(result.stdout.level, 2);
355: });
Difference (- actual, + expected):
- 1
+ 2
› file://test.js:354:4
FORCE_COLOR works when set via command line (all values are strings)
test.js:398
397: t.truthy(result.stdout);
398: t.is(result.stdout.level, 2);
399:
Difference (- actual, + expected):
- 1
+ 2
› file://test.js:398:4
─
2 tests failed
Since, it is a very small change, I didn't bother to make a pull request. However, if you want I can create a pull request. I have the corrected code here.
Miscellaneous
System Information
uname -r
# 6.9.3-arch1-1
I use arch btw
node -v
# v20.14.0
npm -v
# 10.7.0
The text was updated successfully, but these errors were encountered:
Problem
Two test cases are failing, present at
line 44
andline 52
intest.js
(although 4 test cases are failing but I'm considering 2 since I was able to fix only 2, solution is provided below):Solution
test.js
,process.argv
is set as--color=256
andprocess.env.FORCE_COLOR
is set to'true'
and1
.index.js
, atline 80
, we have anif
statement that checks value offorceColor
and returns it,if
condition atline 84
that checks forcolor=256
flag,forceColor
is defined abovecolor=256
inindex.js
. Hence, the value offorceColor
, i.e.,1
is returned whereas expected is2
.forceColor
condition belowcolor=256
condition.Miscellaneous
uname -r # 6.9.3-arch1-1
node -v # v20.14.0
npm -v # 10.7.0
The text was updated successfully, but these errors were encountered: