@@ -167,21 +167,26 @@ suite('Language Server - Activator', () => {
167167 verify ( lsDownloader . downloadLanguageServer ( anything ( ) , undefined ) ) . once ( ) ;
168168 verify ( fs . fileExists ( targetJsonFile ) ) . once ( ) ;
169169 } ) ;
170- test ( 'Do not download nor check if ICU config exists after downloading ' , async ( ) => {
170+ test ( 'Download if contents of ICU config is not as expected ' , async ( ) => {
171171 const languageServerFolder = 'Some folder name' ;
172172 const languageServerFolderPath = path . join ( EXTENSION_ROOT_DIR , languageServerFolder ) ;
173173 const mscorlib = path . join ( languageServerFolderPath , 'mscorlib.dll' ) ;
174174 const targetJsonFile = path . join ( languageServerFolderPath , 'Microsoft.Python.LanguageServer.runtimeconfig.json' ) ;
175+ const jsonContents = { runtimeOptions : { configProperties : { 'System.Globalization.Invariant' : false } } } ;
175176
176177 when ( settings . downloadLanguageServer ) . thenReturn ( true ) ;
177178 when ( lsFolderService . getLanguageServerFolderName ( undefined ) ) . thenResolve ( languageServerFolder ) ;
178- when ( fs . fileExists ( mscorlib ) ) . thenResolve ( true ) ;
179+ when ( fs . fileExists ( mscorlib ) ) . thenResolve ( false ) ;
180+ when ( lsDownloader . downloadLanguageServer ( languageServerFolderPath , undefined ) ) . thenResolve ( ) ;
181+ when ( fs . fileExists ( targetJsonFile ) ) . thenResolve ( true ) ;
182+ when ( fs . readFile ( targetJsonFile ) ) . thenResolve ( JSON . stringify ( jsonContents ) ) ;
179183
180184 await activator . ensureLanguageServerIsAvailable ( undefined ) ;
181185
182186 verify ( lsFolderService . getLanguageServerFolderName ( undefined ) ) . once ( ) ;
183- verify ( lsDownloader . downloadLanguageServer ( anything ( ) , undefined ) ) . never ( ) ;
184- verify ( fs . fileExists ( targetJsonFile ) ) . never ( ) ;
187+ verify ( lsDownloader . downloadLanguageServer ( anything ( ) , undefined ) ) . once ( ) ;
188+ verify ( fs . fileExists ( targetJsonFile ) ) . once ( ) ;
189+ verify ( fs . readFile ( targetJsonFile ) ) . once ( ) ;
185190 } ) ;
186191 test ( 'JSON file is created to ensure LS can start without ICU' , async ( ) => {
187192 const targetJsonFile = path . join ( 'some folder' , 'Microsoft.Python.LanguageServer.runtimeconfig.json' ) ;
@@ -194,14 +199,30 @@ suite('Language Server - Activator', () => {
194199 verify ( fs . fileExists ( targetJsonFile ) ) . atLeast ( 1 ) ;
195200 verify ( fs . writeFile ( targetJsonFile , JSON . stringify ( contents ) ) ) . once ( ) ;
196201 } ) ;
197- test ( 'JSON file is not created if it already exists' , async ( ) => {
202+ test ( 'JSON file is not created if it already exists with the right content ' , async ( ) => {
198203 const targetJsonFile = path . join ( 'some folder' , 'Microsoft.Python.LanguageServer.runtimeconfig.json' ) ;
199204 const contents = { runtimeOptions : { configProperties : { 'System.Globalization.Invariant' : true } } } ;
205+ const existingContents = { runtimeOptions : { configProperties : { 'System.Globalization.Invariant' : true } } } ;
200206 when ( fs . fileExists ( targetJsonFile ) ) . thenResolve ( true ) ;
207+ when ( fs . readFile ( targetJsonFile ) ) . thenResolve ( JSON . stringify ( existingContents ) ) ;
201208
202209 await activator . prepareLanguageServerForNoICU ( 'some folder' ) ;
203210
204211 verify ( fs . fileExists ( targetJsonFile ) ) . atLeast ( 1 ) ;
205212 verify ( fs . writeFile ( targetJsonFile , JSON . stringify ( contents ) ) ) . never ( ) ;
213+ verify ( fs . readFile ( targetJsonFile ) ) . once ( ) ;
214+ } ) ;
215+ test ( 'JSON file is created if it already exists but with the wrong file content' , async ( ) => {
216+ const targetJsonFile = path . join ( 'some folder' , 'Microsoft.Python.LanguageServer.runtimeconfig.json' ) ;
217+ const contents = { runtimeOptions : { configProperties : { 'System.Globalization.Invariant' : true } } } ;
218+ const existingContents = { runtimeOptions : { configProperties : { 'System.Globalization.Invariant' : false } } } ;
219+ when ( fs . fileExists ( targetJsonFile ) ) . thenResolve ( true ) ;
220+ when ( fs . readFile ( targetJsonFile ) ) . thenResolve ( JSON . stringify ( existingContents ) ) ;
221+
222+ await activator . prepareLanguageServerForNoICU ( 'some folder' ) ;
223+
224+ verify ( fs . fileExists ( targetJsonFile ) ) . atLeast ( 1 ) ;
225+ verify ( fs . writeFile ( targetJsonFile , JSON . stringify ( contents ) ) ) . once ( ) ;
226+ verify ( fs . readFile ( targetJsonFile ) ) . once ( ) ;
206227 } ) ;
207228} ) ;
0 commit comments