@@ -8,13 +8,83 @@ import {
88 LOG_LEVEL ,
99 logger ,
1010 shouldLog ,
11+ getLabels ,
1112} from '../logger.js' ;
13+ import { isUnicodeSupported } from '../isUnicodeSupported.js' ;
1214
1315describe ( 'lib/logger' , ( ) => {
1416 afterEach ( ( ) => {
1517 setLogLevel ( LOG_LEVEL . LOG ) ;
1618 } ) ;
1719
20+ describe ( 'isUnicodeSupported()' , ( ) => {
21+ const originalEnv = process . env ;
22+ const originalPlatform = process . platform ;
23+
24+ afterEach ( ( ) => {
25+ process . env = originalEnv ;
26+ Object . defineProperty ( process , 'platform' , {
27+ value : originalPlatform ,
28+ } ) ;
29+ } ) ;
30+
31+ it ( 'returns true on non-win32 when TERM is not linux' , ( ) => {
32+ Object . defineProperty ( process , 'platform' , { value : 'darwin' } ) ;
33+ process . env = { ...originalEnv , TERM : 'xterm-256color' } ;
34+ expect ( isUnicodeSupported ( ) ) . toBe ( true ) ;
35+ } ) ;
36+
37+ it ( 'returns false on non-win32 when TERM is linux' , ( ) => {
38+ Object . defineProperty ( process , 'platform' , { value : 'linux' } ) ;
39+ process . env = { ...originalEnv , TERM : 'linux' } ;
40+ expect ( isUnicodeSupported ( ) ) . toBe ( false ) ;
41+ } ) ;
42+
43+ it ( 'returns true on win32 when WT_SESSION is set' , ( ) => {
44+ Object . defineProperty ( process , 'platform' , { value : 'win32' } ) ;
45+ process . env = { ...originalEnv , WT_SESSION : '1' } ;
46+ expect ( isUnicodeSupported ( ) ) . toBe ( true ) ;
47+ } ) ;
48+
49+ it ( 'returns false on win32 with no unicode-capable env vars' , ( ) => {
50+ Object . defineProperty ( process , 'platform' , { value : 'win32' } ) ;
51+ process . env = { } ;
52+ expect ( isUnicodeSupported ( ) ) . toBe ( false ) ;
53+ } ) ;
54+ } ) ;
55+
56+ describe ( 'getLabels()' , ( ) => {
57+ const originalEnv = process . env ;
58+ const originalPlatform = process . platform ;
59+
60+ afterEach ( ( ) => {
61+ process . env = originalEnv ;
62+ Object . defineProperty ( process , 'platform' , {
63+ value : originalPlatform ,
64+ } ) ;
65+ } ) ;
66+
67+ it ( 'returns unicode labels when unicode is supported' , ( ) => {
68+ Object . defineProperty ( process , 'platform' , { value : 'darwin' } ) ;
69+ process . env = { ...originalEnv , TERM : 'xterm-256color' } ;
70+ const labels = getLabels ( ) ;
71+ expect ( labels . success ) . toBe ( '✔ SUCCESS' ) ;
72+ expect ( labels . warning ) . toBe ( '⚠ WARNING' ) ;
73+ expect ( labels . error ) . toBe ( '✖ ERROR' ) ;
74+ expect ( labels . info ) . toBe ( 'ℹ INFO' ) ;
75+ } ) ;
76+
77+ it ( 'returns ASCII labels when unicode is not supported' , ( ) => {
78+ Object . defineProperty ( process , 'platform' , { value : 'linux' } ) ;
79+ process . env = { ...originalEnv , TERM : 'linux' } ;
80+ const labels = getLabels ( ) ;
81+ expect ( labels . success ) . toBe ( '[SUCCESS]' ) ;
82+ expect ( labels . warning ) . toBe ( '[WARNING]' ) ;
83+ expect ( labels . error ) . toBe ( '[ERROR]' ) ;
84+ expect ( labels . info ) . toBe ( '[INFO]' ) ;
85+ } ) ;
86+ } ) ;
87+
1888 describe ( 'stylize()' , ( ) => {
1989 it ( 'stylizes input' , ( ) => {
2090 const res = stylize ( '[ERROR]' , Styles . error , [ 'test' ] ) ;
0 commit comments