@@ -20,26 +20,29 @@ export class CodeServer {
2020
2121 /**
2222 * Checks if the editor is visible
23- * and reloads until it is
23+ * and that we are connected to the host
24+ *
25+ * Reload until both checks pass
2426 */
25- async reloadUntilEditorIsVisible ( ) {
27+ async reloadUntilEditorIsReady ( ) {
2628 const editorIsVisible = await this . isEditorVisible ( )
29+ const editorIsConnected = await this . isConnected ( )
2730 let reloadCount = 0
2831
2932 // Occassionally code-server timeouts in Firefox
3033 // we're not sure why
3134 // but usually a reload or two fixes it
3235 // TODO@jsjoeio @oxy look into Firefox reconnection/timeout issues
33- while ( ! editorIsVisible ) {
36+ while ( ! editorIsVisible && ! editorIsConnected ) {
3437 // When a reload happens, we want to wait for all resources to be
3538 // loaded completely. Hence why we use that instead of DOMContentLoaded
3639 // Read more: https://thisthat.dev/dom-content-loaded-vs-load/
3740 await this . page . waitForLoadState ( "load" )
3841 // Give it an extra second just in case it's feeling extra slow
3942 await this . page . waitForTimeout ( 1000 )
4043 reloadCount += 1
41- if ( await this . isEditorVisible ( ) ) {
42- console . log ( ` Editor became visible after ${ reloadCount } reloads` )
44+ if ( ( await this . isEditorVisible ( ) ) && ( await this . isConnected ) ) {
45+ console . log ( ` Editor became ready after ${ reloadCount } reloads` )
4346 break
4447 }
4548 await this . page . reload ( )
@@ -56,6 +59,19 @@ export class CodeServer {
5659 return await this . page . isVisible ( this . editorSelector )
5760 }
5861
62+ /**
63+ * Checks if the editor is visible
64+ */
65+ async isConnected ( ) {
66+ await this . page . waitForLoadState ( "networkidle" )
67+
68+ const host = new URL ( CODE_SERVER_ADDRESS ) . host
69+ const hostSelector = `[title="Editing on ${ host } "]`
70+ await this . page . waitForSelector ( hostSelector )
71+
72+ return await this . page . isVisible ( hostSelector )
73+ }
74+
5975 /**
6076 * Focuses Integrated Terminal
6177 * by using "Terminal: Focus Terminal"
@@ -90,12 +106,12 @@ export class CodeServer {
90106
91107 /**
92108 * Navigates to CODE_SERVER_ADDRESS
93- * and reloads until the editor is visible
109+ * and reloads until the editor is ready
94110 *
95111 * Helpful for running before tests
96112 */
97113 async setup ( ) {
98114 await this . navigate ( )
99- await this . reloadUntilEditorIsVisible ( )
115+ await this . reloadUntilEditorIsReady ( )
100116 }
101117}
0 commit comments