@@ -45,9 +45,11 @@ suite('Extension Tests', () => {
4545 'workbench.action.quickOpen' ,
4646 path . join ( projects [ 0 ] , 'src' , 'lib.rs' ) ,
4747 ) ;
48+ await waitForUI ( ) ;
4849 await vscode . commands . executeCommand (
4950 'workbench.action.acceptSelectedQuickOpenItem' ,
5051 ) ;
52+ await waitForUI ( ) ;
5153 await vscode . commands . executeCommand ( 'workbench.action.keepEditor' ) ;
5254 // Wait until the first server is ready
5355 await whenWorkspacesActive [ 0 ] ;
@@ -59,9 +61,11 @@ suite('Extension Tests', () => {
5961 'workbench.action.quickOpen' ,
6062 path . join ( projects [ 1 ] , 'src' , 'lib.rs' ) ,
6163 ) ;
64+ await waitForUI ( ) ;
6265 await vscode . commands . executeCommand (
6366 'workbench.action.acceptSelectedQuickOpenItem' ,
6467 ) ;
68+ await waitForUI ( ) ;
6569 // Wait until the second server is ready
6670 await whenWorkspacesActive [ 1 ] ;
6771 expect ( await fetchBriefTasks ( ) ) . to . include . deep . members ( expected ) ;
@@ -107,3 +111,13 @@ function whenWorkspaceActive(
107111 } ) ;
108112 } ) ;
109113}
114+
115+ const delay = ( ms : number ) => new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
116+ /**
117+ * Returns a promise that resolves after executing the current call stack.
118+ * Sometimes we need to wait for the UI to catch up (since it's executed on the
119+ * same thread as JS) before and UI-dependent logic, such as a sequence of
120+ * user-like inputs. To avoid any races (which unfortunately *did* happen), it's
121+ * best if we interweave the delays between each UI action.
122+ */
123+ const waitForUI = ( ) => delay ( 0 ) ;
0 commit comments