From 2cb499385a0e36d60161618b3360c25408671e10 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Fri, 30 Apr 2021 12:33:20 -0700 Subject: [PATCH] feat: add isConnected method to CodeServer model --- test/e2e/codeServer.test.ts | 4 ++++ test/e2e/models/CodeServer.ts | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/test/e2e/codeServer.test.ts b/test/e2e/codeServer.test.ts index 4b20f69fc..7cd74fa76 100644 --- a/test/e2e/codeServer.test.ts +++ b/test/e2e/codeServer.test.ts @@ -38,6 +38,10 @@ test.describe("CodeServer", () => { expect(await codeServer.isEditorVisible()).toBe(true) }) + test.only("should always have a connection", options, async ({ page }) => { + expect(await codeServer.isConnected()).toBe(true) + }) + test("should show the Integrated Terminal", options, async ({ page }) => { await codeServer.focusTerminal() expect(await page.isVisible("#terminal")).toBe(true) diff --git a/test/e2e/models/CodeServer.ts b/test/e2e/models/CodeServer.ts index b833cc7ef..6142ce25d 100644 --- a/test/e2e/models/CodeServer.ts +++ b/test/e2e/models/CodeServer.ts @@ -56,6 +56,25 @@ export class CodeServer { return await this.page.isVisible(this.editorSelector) } + /** + * Checks if the editor is visible + */ + async isConnected() { + await this.page.waitForLoadState("networkidle") + + // See [aria-label="Remote Host"] + const hostElement = await this.page.$(`[aria-label="Remote Host"]`) + // Returns something like " localhost:8080" + const host = await hostElement?.innerText() + + // Check if host (localhost:8080) is in the CODE_SERVER_ADDRESS + // if it is, we're connected! + // if not, we may need to reload the page + // Make sure to trim whitespace too + const isEditorConnected = host ? CODE_SERVER_ADDRESS.includes(host.trim()) : false + return isEditorConnected + } + /** * Focuses Integrated Terminal * by using "Terminal: Focus Terminal"