@@ -78,13 +78,17 @@ describe('androidStudio', () => {
7878 it ( 'detects Android Studio in the fallback Windows installation path' , async ( ) => {
7979 // Make CLI think Android Studio was not found
8080 environmentInfo . IDEs [ 'Android Studio' ] = 'Not Found' ;
81- // Force the platform to win32 for the test
82- const platformSpy = jest
83- . spyOn ( process , 'platform' , 'get' )
84- . mockReturnValue ( 'win32' ) ;
81+ // Force platform to win32 for the test
82+ // TODO: use cleaner jest.replaceProperty in jest 29+
83+ const originalPlatform = process . platform ;
84+ Object . defineProperty ( process , 'platform' , {
85+ value : 'win32' ,
86+ writable : true ,
87+ configurable : true ,
88+ } ) ;
8589
8690 // First WMIC (primary) returns empty, second (fallback) returns version
87- ( execa as jest . Mock )
91+ ( execa as unknown as jest . Mock )
8892 . mockResolvedValueOnce ( { stdout : '' } )
8993 . mockResolvedValueOnce ( { stdout : '4.2.1.0' } ) ;
9094
@@ -93,26 +97,42 @@ describe('androidStudio', () => {
9397 expect ( diagnostics . needsToBeFixed ) . toBe ( false ) ;
9498 expect ( diagnostics . version ) . toBe ( '4.2.1.0' ) ;
9599
96- platformSpy . mockRestore ( ) ;
100+ // Restore original platform
101+ // TODO: use cleaner mockRestore in jest 29+
102+ Object . defineProperty ( process , 'platform' , {
103+ value : originalPlatform ,
104+ writable : true ,
105+ configurable : true ,
106+ } ) ;
97107 } ) ;
98108
99109 it ( 'detects when Android Studio is also not in fallback installation path' , async ( ) => {
100110 // Make CLI think Android Studio was not found
101111 environmentInfo . IDEs [ 'Android Studio' ] = 'Not Found' ;
102112 // Force the platform to win32 for the test
103- const platformSpy = jest
104- . spyOn ( process , 'platform' , 'get' )
105- . mockReturnValue ( 'win32' ) ;
113+ // TODO: use cleaner jest.replaceProperty in jest 29+
114+ const originalPlatform = process . platform ;
115+ Object . defineProperty ( process , 'platform' , {
116+ value : 'win32' ,
117+ writable : true ,
118+ configurable : true ,
119+ } ) ;
106120
107121 // First WMIC (primary) returns empty, second (fallback) returns version
108- ( execa as jest . Mock )
122+ ( execa as unknown as jest . Mock )
109123 . mockResolvedValueOnce ( { stdout : '' } )
110124 . mockResolvedValueOnce ( { stdout : '' } ) ;
111125
112126 const diagnostics = await androidStudio . getDiagnostics ( environmentInfo ) ;
113127
114128 expect ( diagnostics . needsToBeFixed ) . toBe ( true ) ;
115129
116- platformSpy . mockRestore ( ) ;
130+ // Restore original platform
131+ // TODO: use cleaner mockRestore in jest 29+
132+ Object . defineProperty ( process , 'platform' , {
133+ value : originalPlatform ,
134+ writable : true ,
135+ configurable : true ,
136+ } ) ;
117137 } ) ;
118138} ) ;
0 commit comments