@@ -80,16 +80,28 @@ describe('cli smart_sig', () => {
8080 } )
8181
8282 it ( 'fails when credentials are missing' , async ( ) => {
83+ const originalKey = process . env . TRANSLOADIT_KEY
84+ const originalSecret = process . env . TRANSLOADIT_SECRET
85+ delete process . env . TRANSLOADIT_KEY
86+ delete process . env . TRANSLOADIT_SECRET
87+
8388 const stdoutSpy = vi . spyOn ( process . stdout , 'write' ) . mockImplementation ( ( ) => true )
8489 const stderrSpy = vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
8590
86- await runSmartSig ( '{}' )
91+ try {
92+ await runSmartSig ( '{}' )
8793
88- expect ( stdoutSpy ) . not . toHaveBeenCalled ( )
89- expect ( stderrSpy ) . toHaveBeenCalledWith (
90- 'Missing credentials. Please set TRANSLOADIT_KEY and TRANSLOADIT_SECRET environment variables.' ,
91- )
92- expect ( process . exitCode ) . toBe ( 1 )
94+ expect ( stdoutSpy ) . not . toHaveBeenCalled ( )
95+ expect ( stderrSpy ) . toHaveBeenCalledWith (
96+ 'Missing credentials. Please set TRANSLOADIT_KEY and TRANSLOADIT_SECRET environment variables.' ,
97+ )
98+ expect ( process . exitCode ) . toBe ( 1 )
99+ } finally {
100+ if ( originalKey != null ) process . env . TRANSLOADIT_KEY = originalKey
101+ else delete process . env . TRANSLOADIT_KEY
102+ if ( originalSecret != null ) process . env . TRANSLOADIT_SECRET = originalSecret
103+ else delete process . env . TRANSLOADIT_SECRET
104+ }
93105 } )
94106
95107 it ( 'fails when stdin is not valid JSON' , async ( ) => {
0 commit comments