Skip to content

Commit a5926aa

Browse files
committed
refactor: change to reloadUntilEditorIsReady
1 parent 2cb4993 commit a5926aa

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

test/e2e/codeServer.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test.describe("CodeServer", () => {
3838
expect(await codeServer.isEditorVisible()).toBe(true)
3939
})
4040

41-
test.only("should always have a connection", options, async ({ page }) => {
41+
test("should always have a connection", options, async ({ page }) => {
4242
expect(await codeServer.isConnected()).toBe(true)
4343
})
4444

test/e2e/login.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ test.describe("login", () => {
3030
await page.waitForLoadState("networkidle")
3131
// We do this because occassionally code-server doesn't load on Firefox
3232
// but loads if you reload once or twice
33-
await codeServer.reloadUntilEditorIsVisible()
33+
await codeServer.reloadUntilEditorIsReady()
3434
// Make sure the editor actually loaded
3535
expect(await codeServer.isEditorVisible()).toBe(true)
3636
})

test/e2e/logout.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ test.describe("logout", () => {
2525
await page.waitForLoadState("networkidle")
2626
// We do this because occassionally code-server doesn't load on Firefox
2727
// but loads if you reload once or twice
28-
await codeServer.reloadUntilEditorIsVisible()
28+
await codeServer.reloadUntilEditorIsReady()
2929
// Make sure the editor actually loaded
3030
expect(await codeServer.isEditorVisible()).toBe(true)
3131

test/e2e/models/CodeServer.ts

+16-17
Original file line numberDiff line numberDiff line change
@@ -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()
@@ -62,17 +65,13 @@ export class CodeServer {
6265
async isConnected() {
6366
await this.page.waitForLoadState("networkidle")
6467

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+
// Slices http://localhost:8080
69+
// to localhost:8080
70+
const hostWithoutHttp = CODE_SERVER_ADDRESS.slice(7)
71+
const hostSelector = `[title="Editing on ${hostWithoutHttp}"]`
72+
await this.page.waitForSelector(hostSelector)
6973

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
74+
return await this.page.isVisible(hostSelector)
7675
}
7776

7877
/**
@@ -109,12 +108,12 @@ export class CodeServer {
109108

110109
/**
111110
* Navigates to CODE_SERVER_ADDRESS
112-
* and reloads until the editor is visible
111+
* and reloads until the editor is ready
113112
*
114113
* Helpful for running before tests
115114
*/
116115
async setup() {
117116
await this.navigate()
118-
await this.reloadUntilEditorIsVisible()
117+
await this.reloadUntilEditorIsReady()
119118
}
120119
}

0 commit comments

Comments
 (0)