@@ -8,11 +8,16 @@ sandboxTest.skipIf(isDebug)('env vars', async () => {
88  const  sandbox  =  await  Sandbox . create ( { 
99    envs : {  TEST_ENV_VAR : 'supertest'  } , 
1010  } ) 
11-   const  result  =  await  sandbox . runCode ( 
12-     `import os; x = os.getenv('TEST_ENV_VAR'); x` 
13-   ) 
1411
15-   expect ( result . results [ 0 ] . text . trim ( ) ) . toEqual ( 'supertest' ) 
12+   try  { 
13+     const  result  =  await  sandbox . runCode ( 
14+       `import os; x = os.getenv('TEST_ENV_VAR'); x` 
15+     ) 
16+ 
17+     expect ( result . results [ 0 ] . text . trim ( ) ) . toEqual ( 'supertest' ) 
18+   }  finally  { 
19+     await  sandbox . kill ( ) 
20+   } 
1621} ) 
1722
1823sandboxTest ( 'env vars on sandbox' ,  async  ( {  sandbox } )  =>  { 
@@ -28,28 +33,33 @@ sandboxTest('env vars on sandbox override', async () => {
2833  const  sandbox  =  await  Sandbox . create ( { 
2934    envs : {  FOO : 'bar' ,  SBX : 'value'  } , 
3035  } ) 
31-   await  sandbox . runCode ( 
32-     "import os; os.environ['FOO'] = 'bar'; os.environ['RUNTIME_ENV'] = 'js_runtime'" 
33-   ) 
34-   const  result  =  await  sandbox . runCode ( 
35-     "import os; os.getenv('FOO')" , 
36-     {  envs : {  FOO : 'baz'  }  } 
37-   ) 
3836
39-   expect ( result . results [ 0 ] . text . trim ( ) ) . toEqual ( 'baz' ) 
37+   try  { 
38+     await  sandbox . runCode ( 
39+       "import os; os.environ['FOO'] = 'bar'; os.environ['RUNTIME_ENV'] = 'js_runtime'" 
40+     ) 
41+     const  result  =  await  sandbox . runCode ( 
42+       "import os; os.getenv('FOO')" , 
43+       {  envs : {  FOO : 'baz'  }  } 
44+     ) 
4045
41-   const  result2  =  await  sandbox . runCode ( 
42-     "import os; os.getenv('RUNTIME_ENV')" 
43-   ) 
44-   expect ( result2 . results [ 0 ] . text . trim ( ) ) . toEqual ( 'js_runtime' ) 
46+     expect ( result . results [ 0 ] . text . trim ( ) ) . toEqual ( 'baz' ) 
4547
46-   if  ( ! isDebug )  { 
47-     const  result3  =  await  sandbox . runCode ( 
48-       "import os; os.getenv('SBX')" 
48+     const  result2  =  await  sandbox . runCode ( 
49+       "import os; os.getenv('RUNTIME_ENV')" 
4950    ) 
50-     expect ( result3 . results [ 0 ] . text . trim ( ) ) . toEqual ( 'value' ) 
51-   } 
51+     expect ( result2 . results [ 0 ] . text . trim ( ) ) . toEqual ( 'js_runtime' ) 
52+ 
53+     if  ( ! isDebug )  { 
54+       const  result3  =  await  sandbox . runCode ( 
55+         "import os; os.getenv('SBX')" 
56+       ) 
57+       expect ( result3 . results [ 0 ] . text . trim ( ) ) . toEqual ( 'value' ) 
58+     } 
5259
53-   const  result4  =  await  sandbox . runCode ( "import os; os.getenv('FOO')" ) 
54-   expect ( result4 . results [ 0 ] . text . trim ( ) ) . toEqual ( 'bar' ) 
60+     const  result4  =  await  sandbox . runCode ( "import os; os.getenv('FOO')" ) 
61+     expect ( result4 . results [ 0 ] . text . trim ( ) ) . toEqual ( 'bar' ) 
62+   }  finally  { 
63+     await  sandbox . kill ( ) 
64+   } 
5565} ) 
0 commit comments