@@ -56,7 +56,10 @@ describe("ExecaTerminalProcess", () => {
5656 } )
5757
5858 describe ( "UTF-8 encoding fix" , ( ) => {
59- it ( "should set LANG and LC_ALL to en_US.UTF-8" , async ( ) => {
59+ it ( "should set LANG and LC_ALL to en_US.UTF-8 when no locale is set" , async ( ) => {
60+ delete process . env . LANG
61+ delete process . env . LC_ALL
62+ terminalProcess = new ExecaTerminalProcess ( mockTerminal )
6063 await terminalProcess . run ( "echo test" )
6164 const execaMock = vitest . mocked ( execa )
6265 expect ( execaMock ) . toHaveBeenCalledWith (
@@ -81,9 +84,49 @@ describe("ExecaTerminalProcess", () => {
8184 expect ( calledOptions . env . EXISTING_VAR ) . toBe ( "existing" )
8285 } )
8386
84- it ( "should override existing LANG and LC_ALL values" , async ( ) => {
85- process . env . LANG = "C"
86- process . env . LC_ALL = "POSIX"
87+ it ( "should convert Chinese GBK locale to UTF-8" , async ( ) => {
88+ process . env . LANG = "zh_CN.GBK"
89+ terminalProcess = new ExecaTerminalProcess ( mockTerminal )
90+ await terminalProcess . run ( "echo test" )
91+ const execaMock = vitest . mocked ( execa )
92+ const calledOptions = execaMock . mock . calls [ 0 ] [ 0 ] as any
93+ expect ( calledOptions . env . LANG ) . toBe ( "zh_CN.UTF-8" )
94+ expect ( calledOptions . env . LC_ALL ) . toBe ( "zh_CN.UTF-8" )
95+ } )
96+
97+ it ( "should convert Japanese locale to UTF-8" , async ( ) => {
98+ process . env . LANG = "ja_JP.SJIS"
99+ terminalProcess = new ExecaTerminalProcess ( mockTerminal )
100+ await terminalProcess . run ( "echo test" )
101+ const execaMock = vitest . mocked ( execa )
102+ const calledOptions = execaMock . mock . calls [ 0 ] [ 0 ] as any
103+ expect ( calledOptions . env . LANG ) . toBe ( "ja_JP.UTF-8" )
104+ expect ( calledOptions . env . LC_ALL ) . toBe ( "ja_JP.UTF-8" )
105+ } )
106+
107+ it ( "should handle locale from LC_ALL when LANG is not set" , async ( ) => {
108+ delete process . env . LANG
109+ process . env . LC_ALL = "ko_KR.EUC-KR"
110+ terminalProcess = new ExecaTerminalProcess ( mockTerminal )
111+ await terminalProcess . run ( "echo test" )
112+ const execaMock = vitest . mocked ( execa )
113+ const calledOptions = execaMock . mock . calls [ 0 ] [ 0 ] as any
114+ expect ( calledOptions . env . LANG ) . toBe ( "ko_KR.UTF-8" )
115+ expect ( calledOptions . env . LC_ALL ) . toBe ( "ko_KR.UTF-8" )
116+ } )
117+
118+ it ( "should handle already UTF-8 locale" , async ( ) => {
119+ process . env . LANG = "zh_CN.UTF-8"
120+ terminalProcess = new ExecaTerminalProcess ( mockTerminal )
121+ await terminalProcess . run ( "echo test" )
122+ const execaMock = vitest . mocked ( execa )
123+ const calledOptions = execaMock . mock . calls [ 0 ] [ 0 ] as any
124+ expect ( calledOptions . env . LANG ) . toBe ( "zh_CN.UTF-8" )
125+ expect ( calledOptions . env . LC_ALL ) . toBe ( "zh_CN.UTF-8" )
126+ } )
127+
128+ it ( "should fallback to en_US.UTF-8 for invalid locale format" , async ( ) => {
129+ process . env . LANG = "invalid_locale"
87130 terminalProcess = new ExecaTerminalProcess ( mockTerminal )
88131 await terminalProcess . run ( "echo test" )
89132 const execaMock = vitest . mocked ( execa )
0 commit comments