@@ -22,15 +22,11 @@ describe('EnvironmentManager integration', () => {
2222 const envPath = path . join ( testDir , '.env' )
2323
2424 // Create .env file
25- const result1 = await manager . setEnvVar ( envPath , 'DATABASE_URL' , 'postgres://localhost/db' )
26- expect ( result1 . success ) . toBe ( true )
25+ await manager . setEnvVar ( envPath , 'DATABASE_URL' , 'postgres://localhost/db' )
2726
2827 // Add more variables
29- const result2 = await manager . setEnvVar ( envPath , 'API_KEY' , 'test-key-123' )
30- expect ( result2 . success ) . toBe ( true )
31-
32- const result3 = await manager . setEnvVar ( envPath , 'NODE_ENV' , 'development' )
33- expect ( result3 . success ) . toBe ( true )
28+ await manager . setEnvVar ( envPath , 'API_KEY' , 'test-key-123' )
29+ await manager . setEnvVar ( envPath , 'NODE_ENV' , 'development' )
3430
3531 // Set port for workspace
3632 const port = await manager . setPortForWorkspace ( envPath , 42 )
@@ -77,8 +73,7 @@ NODE_ENV="development"`
7773 await fs . writeFile ( envPath , initialContent , 'utf8' )
7874
7975 // Update a value
80- const result = await manager . setEnvVar ( envPath , 'API_KEY' , 'new-key' )
81- expect ( result . success ) . toBe ( true )
76+ await manager . setEnvVar ( envPath , 'API_KEY' , 'new-key' )
8277
8378 // Read the file content directly
8479 const fileContent = await fs . readFile ( envPath , 'utf8' )
@@ -105,24 +100,24 @@ NODE_ENV="development"`
105100 await manager . setEnvVar ( envPath , 'KEY2' , 'value2' )
106101
107102 // Update with backup
108- const result = await manager . setEnvVar ( envPath , 'KEY1' , 'new-value' , true )
109- expect ( result . success ) . toBe ( true )
110- expect ( result . backupPath ) . toBeDefined ( )
103+ const backupPath = await manager . setEnvVar ( envPath , 'KEY1' , 'new-value' , true )
104+ expect ( backupPath ) . toBeDefined ( )
105+ expect ( typeof backupPath ) . toBe ( 'string' )
111106
112107 // Verify backup exists
113- const backupExists = await fs . pathExists ( result . backupPath ! )
108+ const backupExists = await fs . pathExists ( backupPath as string )
114109 expect ( backupExists ) . toBe ( true )
115110
116111 // Verify backup contains old value
117- const backupContent = await fs . readFile ( result . backupPath ! , 'utf8' )
112+ const backupContent = await fs . readFile ( backupPath as string , 'utf8' )
118113 expect ( backupContent ) . toContain ( 'KEY1="value1"' )
119114
120115 // Verify main file has new value
121116 const mainContent = await manager . readEnvFile ( envPath )
122117 expect ( mainContent . get ( 'KEY1' ) ) . toBe ( 'new-value' )
123118
124119 // Recovery: restore from backup
125- await manager . copyEnvFile ( result . backupPath ! , envPath )
120+ await manager . copyEnvFile ( backupPath as string , envPath )
126121 const restoredContent = await manager . readEnvFile ( envPath )
127122 expect ( restoredContent . get ( 'KEY1' ) ) . toBe ( 'value1' )
128123 } )
@@ -139,8 +134,7 @@ NODE_ENV="development"`
139134 ]
140135
141136 for ( const [ key , value ] of specialValues ) {
142- const result = await manager . setEnvVar ( envPath , key , value )
143- expect ( result . success ) . toBe ( true )
137+ await manager . setEnvVar ( envPath , key , value )
144138 }
145139
146140 // Read back and verify
@@ -183,12 +177,10 @@ NODE_ENV="development"`
183177 it ( 'should handle missing directories gracefully' , async ( ) => {
184178 const envPath = path . join ( testDir , 'nonexistent' , 'directory' , '.env' )
185179
186- // Should fail because parent directory doesn't exist
187- const result = await manager . setEnvVar ( envPath , 'KEY' , 'value' )
188-
189- expect ( result . success ) . toBe ( false )
190- expect ( result . error ) . toBeDefined ( )
191- expect ( result . error ) . toContain ( 'no such file or directory' )
180+ // Should throw because parent directory doesn't exist
181+ await expect (
182+ manager . setEnvVar ( envPath , 'KEY' , 'value' )
183+ ) . rejects . toThrow ( 'no such file or directory' )
192184 } )
193185
194186 it ( 'should handle read-only files' , async ( ) => {
@@ -197,10 +189,10 @@ NODE_ENV="development"`
197189 await fs . writeFile ( envPath , 'KEY="value"' , 'utf8' )
198190 await fs . chmod ( envPath , 0o444 ) // Read-only
199191
200- const result = await manager . setEnvVar ( envPath , 'KEY' , 'new-value' )
201-
202- expect ( result . success ) . toBe ( false )
203- expect ( result . error ) . toBeDefined ( )
192+ // Should throw because file is read-only
193+ await expect (
194+ manager . setEnvVar ( envPath , 'KEY' , 'new-value' )
195+ ) . rejects . toThrow ( 'permission denied' )
204196
205197 // Cleanup
206198 await fs . chmod ( envPath , 0o644 )
@@ -231,23 +223,20 @@ _VALID_KEY="value"`
231223 const envPath = path . join ( testDir , '.env' )
232224
233225 // Test case 1: Create new file
234- const result1 = await manager . setEnvVar ( envPath , 'KEY' , 'value' )
235- expect ( result1 . success ) . toBe ( true )
226+ await manager . setEnvVar ( envPath , 'KEY' , 'value' )
236227
237228 let content = await fs . readFile ( envPath , 'utf8' )
238229 expect ( content ) . toBe ( 'KEY="value"' )
239230
240231 // Test case 2: Add variable to existing file
241- const result2 = await manager . setEnvVar ( envPath , 'KEY2' , 'value2' )
242- expect ( result2 . success ) . toBe ( true )
232+ await manager . setEnvVar ( envPath , 'KEY2' , 'value2' )
243233
244234 content = await fs . readFile ( envPath , 'utf8' )
245235 expect ( content ) . toContain ( 'KEY="value"' )
246236 expect ( content ) . toContain ( 'KEY2="value2"' )
247237
248238 // Test case 3: Update existing variable
249- const result3 = await manager . setEnvVar ( envPath , 'KEY' , 'new-value' )
250- expect ( result3 . success ) . toBe ( true )
239+ await manager . setEnvVar ( envPath , 'KEY' , 'new-value' )
251240
252241 content = await fs . readFile ( envPath , 'utf8' )
253242 expect ( content ) . toContain ( 'KEY="new-value"' )
@@ -270,8 +259,7 @@ _VALID_KEY="value"`
270259
271260 // The bash script uses: escaped_value="${var_value//\"/\\\"}"
272261 const valueWithQuotes = 'value with "quotes" inside'
273- const result = await manager . setEnvVar ( envPath , 'KEY' , valueWithQuotes )
274- expect ( result . success ) . toBe ( true )
262+ await manager . setEnvVar ( envPath , 'KEY' , valueWithQuotes )
275263
276264 const fileContent = await fs . readFile ( envPath , 'utf8' )
277265 expect ( fileContent ) . toBe ( 'KEY="value with \\"quotes\\" inside"' )
0 commit comments