@@ -45,9 +45,11 @@ suite('Extension Tests', () => {
45
45
'workbench.action.quickOpen' ,
46
46
path . join ( projects [ 0 ] , 'src' , 'lib.rs' ) ,
47
47
) ;
48
+ await waitForUI ( ) ;
48
49
await vscode . commands . executeCommand (
49
50
'workbench.action.acceptSelectedQuickOpenItem' ,
50
51
) ;
52
+ await waitForUI ( ) ;
51
53
await vscode . commands . executeCommand ( 'workbench.action.keepEditor' ) ;
52
54
// Wait until the first server is ready
53
55
await whenWorkspacesActive [ 0 ] ;
@@ -59,9 +61,11 @@ suite('Extension Tests', () => {
59
61
'workbench.action.quickOpen' ,
60
62
path . join ( projects [ 1 ] , 'src' , 'lib.rs' ) ,
61
63
) ;
64
+ await waitForUI ( ) ;
62
65
await vscode . commands . executeCommand (
63
66
'workbench.action.acceptSelectedQuickOpenItem' ,
64
67
) ;
68
+ await waitForUI ( ) ;
65
69
// Wait until the second server is ready
66
70
await whenWorkspacesActive [ 1 ] ;
67
71
expect ( await fetchBriefTasks ( ) ) . to . include . deep . members ( expected ) ;
@@ -107,3 +111,13 @@ function whenWorkspaceActive(
107
111
} ) ;
108
112
} ) ;
109
113
}
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