@@ -20,26 +20,29 @@ export class CodeServer {
20
20
21
21
/**
22
22
* 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
24
26
*/
25
- async reloadUntilEditorIsVisible ( ) {
27
+ async reloadUntilEditorIsReady ( ) {
26
28
const editorIsVisible = await this . isEditorVisible ( )
29
+ const editorIsConnected = await this . isConnected ( )
27
30
let reloadCount = 0
28
31
29
32
// Occassionally code-server timeouts in Firefox
30
33
// we're not sure why
31
34
// but usually a reload or two fixes it
32
35
// TODO@jsjoeio @oxy look into Firefox reconnection/timeout issues
33
- while ( ! editorIsVisible ) {
36
+ while ( ! editorIsVisible && ! editorIsConnected ) {
34
37
// When a reload happens, we want to wait for all resources to be
35
38
// loaded completely. Hence why we use that instead of DOMContentLoaded
36
39
// Read more: https://thisthat.dev/dom-content-loaded-vs-load/
37
40
await this . page . waitForLoadState ( "load" )
38
41
// Give it an extra second just in case it's feeling extra slow
39
42
await this . page . waitForTimeout ( 1000 )
40
43
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` )
43
46
break
44
47
}
45
48
await this . page . reload ( )
@@ -62,17 +65,11 @@ export class CodeServer {
62
65
async isConnected ( ) {
63
66
await this . page . waitForLoadState ( "networkidle" )
64
67
65
- // See [aria-label="Remote Host"]
66
- const hostElement = await this . page . $ ( `[aria-label="Remote Host"]` )
67
- // Returns something like " localhost:8080"
68
- const host = await hostElement ?. innerText ( )
68
+ const host = new URL ( CODE_SERVER_ADDRESS ) . host
69
+ const hostSelector = `[title="Editing on ${ host } "]`
70
+ await this . page . waitForSelector ( hostSelector )
69
71
70
- // Check if host (localhost:8080) is in the CODE_SERVER_ADDRESS
71
- // if it is, we're connected!
72
- // if not, we may need to reload the page
73
- // Make sure to trim whitespace too
74
- const isEditorConnected = host ? CODE_SERVER_ADDRESS . includes ( host . trim ( ) ) : false
75
- return isEditorConnected
72
+ return await this . page . isVisible ( hostSelector )
76
73
}
77
74
78
75
/**
@@ -109,12 +106,12 @@ export class CodeServer {
109
106
110
107
/**
111
108
* Navigates to CODE_SERVER_ADDRESS
112
- * and reloads until the editor is visible
109
+ * and reloads until the editor is ready
113
110
*
114
111
* Helpful for running before tests
115
112
*/
116
113
async setup ( ) {
117
114
await this . navigate ( )
118
- await this . reloadUntilEditorIsVisible ( )
115
+ await this . reloadUntilEditorIsReady ( )
119
116
}
120
117
}
0 commit comments