@@ -98,8 +98,12 @@ define(function (require, exports, module) {
9898 await _writeKeyboardJson ( KeyBindingManager . _getUserKeyMapFilePath ( ) ) ;
9999 await KeyBindingManager . _loadUserKeyMapImmediate ( ) ;
100100 await awaitsFor ( async ( ) => {
101- const textJson = JSON . parse ( await _readKeyboardJson ( KeyBindingManager . _getUserKeyMapFilePath ( ) ) ) ;
102- return Object . keys ( textJson . overrides ) . length === 0 ;
101+ try {
102+ const textJson = JSON . parse ( await _readKeyboardJson ( KeyBindingManager . _getUserKeyMapFilePath ( ) ) ) ;
103+ return Object . keys ( textJson . overrides ) . length === 0 ;
104+ } catch ( e ) {
105+ return false ; // file may be mid-write; retry on next poll
106+ }
103107 } , "reset user shortcuts" ) ;
104108 await awaitsFor ( ( ) => {
105109 const binding = KeyBindingManager . getKeyBindings ( Commands . EDIT_BEAUTIFY_CODE ) ;
@@ -203,26 +207,38 @@ define(function (require, exports, module) {
203207 testWindow . $ ( ".change-shortcut-dialog .Remove" ) . click ( ) ;
204208 let existingBinding = KeyBindingManager . getKeyBindings ( Commands . EDIT_BEAUTIFY_CODE ) ;
205209 await awaitsFor ( async ( ) => {
206- const textJson = JSON . parse ( await _readKeyboardJson ( KeyBindingManager . _getUserKeyMapFilePath ( ) ) ) ;
207- return textJson . overrides [ existingBinding [ 0 ] . key ] === null ;
210+ try {
211+ const textJson = JSON . parse ( await _readKeyboardJson ( KeyBindingManager . _getUserKeyMapFilePath ( ) ) ) ;
212+ return textJson . overrides [ existingBinding [ 0 ] . key ] === null ;
213+ } catch ( e ) {
214+ return false ; // file may be mid-write; retry on next poll
215+ }
208216 } , "command to be removed" ) ;
209217 } ) ;
210218
211219 it ( "Should be able to assign Function key shortcut association" , async function ( ) {
212220 await editShortcut ( Commands . EDIT_BEAUTIFY_CODE ) ;
213221 keyboardType ( 'F6' ) ;
214222 await awaitsFor ( async ( ) => {
215- const textJson = JSON . parse ( await _readKeyboardJson ( KeyBindingManager . _getUserKeyMapFilePath ( ) ) ) ;
216- return textJson . overrides [ 'F6' ] === Commands . EDIT_BEAUTIFY_CODE ;
223+ try {
224+ const textJson = JSON . parse ( await _readKeyboardJson ( KeyBindingManager . _getUserKeyMapFilePath ( ) ) ) ;
225+ return textJson . overrides [ 'F6' ] === Commands . EDIT_BEAUTIFY_CODE ;
226+ } catch ( e ) {
227+ return false ; // file may be mid-write; retry on next poll
228+ }
217229 } , "F6 to be assigned" ) ;
218230 } ) ;
219231
220232 it ( "Should be able to assign Shift-Function key shortcut association" , async function ( ) {
221233 await editShortcut ( Commands . EDIT_BEAUTIFY_CODE ) ;
222234 keyboardType ( 'Shift-F6' ) ;
223235 await awaitsFor ( async ( ) => {
224- const textJson = JSON . parse ( await _readKeyboardJson ( KeyBindingManager . _getUserKeyMapFilePath ( ) ) ) ;
225- return textJson . overrides [ 'Shift-F6' ] === Commands . EDIT_BEAUTIFY_CODE ;
236+ try {
237+ const textJson = JSON . parse ( await _readKeyboardJson ( KeyBindingManager . _getUserKeyMapFilePath ( ) ) ) ;
238+ return textJson . overrides [ 'Shift-F6' ] === Commands . EDIT_BEAUTIFY_CODE ;
239+ } catch ( e ) {
240+ return false ; // file may be mid-write; retry on next poll
241+ }
226242 } , "Shift-F6 to be assigned" ) ;
227243 } ) ;
228244
@@ -246,8 +262,12 @@ define(function (require, exports, module) {
246262 expect ( testWindow . $ ( ".change-shortcut-dialog .Assign" ) . is ( ":visible" ) ) . toBeTrue ( ) ;
247263 testWindow . $ ( ".change-shortcut-dialog .Assign" ) . click ( ) ;
248264 await awaitsFor ( async ( ) => {
249- const textJson = JSON . parse ( await _readKeyboardJson ( KeyBindingManager . _getUserKeyMapFilePath ( ) ) ) ;
250- return textJson . overrides [ 'F1' ] === Commands . EDIT_BEAUTIFY_CODE ;
265+ try {
266+ const textJson = JSON . parse ( await _readKeyboardJson ( KeyBindingManager . _getUserKeyMapFilePath ( ) ) ) ;
267+ return textJson . overrides [ 'F1' ] === Commands . EDIT_BEAUTIFY_CODE ;
268+ } catch ( e ) {
269+ return false ; // file may be mid-write; retry on next poll
270+ }
251271 } , "F1 to be assigned" ) ;
252272 } ) ;
253273
@@ -262,8 +282,14 @@ define(function (require, exports, module) {
262282 expect ( testWindow . $ ( ".change-shortcut-dialog .Assign" ) . is ( ":visible" ) ) . toBeTrue ( ) ;
263283 testWindow . $ ( ".change-shortcut-dialog .Cancel" ) . click ( ) ;
264284 await awaits ( 200 ) ;
265- const textJson = JSON . parse ( await _readKeyboardJson ( KeyBindingManager . _getUserKeyMapFilePath ( ) ) ) ;
266- expect ( textJson . overrides ) . toEql ( { } ) ;
285+ await awaitsFor ( async ( ) => {
286+ try {
287+ const textJson = JSON . parse ( await _readKeyboardJson ( KeyBindingManager . _getUserKeyMapFilePath ( ) ) ) ;
288+ return Object . keys ( textJson . overrides ) . length === 0 ;
289+ } catch ( e ) {
290+ return false ; // file may be mid-write; retry on next poll
291+ }
292+ } , "overrides to be empty" ) ;
267293 expect ( testWindow . $ ( ".change-shortcut-dialog" ) . is ( ":visible" ) ) . toBeFalse ( ) ;
268294 } ) ;
269295
0 commit comments