From 8352a22e33c28f766cc87ee3586a16d5a003e2d7 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Mon, 22 Aug 2022 12:47:36 -0700 Subject: [PATCH] fix(testing): reduce flakiness in extension e2e tests (#5481) --- test/e2e/extensions.test.ts | 6 ++++-- test/e2e/extensions/test-extension/extension.ts | 3 ++- test/e2e/extensions/test-extension/package.json | 2 +- test/e2e/models/CodeServer.ts | 10 ++++++++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/test/e2e/extensions.test.ts b/test/e2e/extensions.test.ts index 5f42cbb5c..1460e2910 100644 --- a/test/e2e/extensions.test.ts +++ b/test/e2e/extensions.test.ts @@ -8,12 +8,14 @@ function runTestExtensionTests() { test("should have access to VSCODE_PROXY_URI", async ({ codeServerPage }) => { const address = await getMaybeProxiedCodeServer(codeServerPage) + await codeServerPage.waitForTestExtensionLoaded() await codeServerPage.executeCommandViaMenus("code-server: Get proxy URI") - const text = await codeServerPage.page.locator(".notification-list-item-message").textContent() + await codeServerPage.page.waitForSelector("text=proxyUri", { timeout: 3000 }) + const text = await codeServerPage.page.locator("text=proxyUri").first().textContent() // Remove end slash in address const normalizedAddress = address.replace(/\/+$/, "") - expect(text).toBe(`${normalizedAddress}/proxy/{{port}}`) + expect(text).toBe(`Info: proxyUri: ${normalizedAddress}/proxy/{{port}}`) }) } diff --git a/test/e2e/extensions/test-extension/extension.ts b/test/e2e/extensions/test-extension/extension.ts index dcbd6dde7..ea962efbd 100644 --- a/test/e2e/extensions/test-extension/extension.ts +++ b/test/e2e/extensions/test-extension/extension.ts @@ -1,10 +1,11 @@ import * as vscode from "vscode" export function activate(context: vscode.ExtensionContext) { + vscode.window.showInformationMessage("test extension loaded") context.subscriptions.push( vscode.commands.registerCommand("codeServerTest.proxyUri", () => { if (process.env.VSCODE_PROXY_URI) { - vscode.window.showInformationMessage(process.env.VSCODE_PROXY_URI) + vscode.window.showInformationMessage(`proxyUri: ${process.env.VSCODE_PROXY_URI}`) } else { vscode.window.showErrorMessage("No proxy URI was set") } diff --git a/test/e2e/extensions/test-extension/package.json b/test/e2e/extensions/test-extension/package.json index 5d32de7ac..4a9db00d5 100644 --- a/test/e2e/extensions/test-extension/package.json +++ b/test/e2e/extensions/test-extension/package.json @@ -4,7 +4,7 @@ "version": "0.0.1", "publisher": "coder", "activationEvents": [ - "onCommand:codeServerTest.proxyUri" + "onStartupFinished" ], "engines": { "vscode": "^1.56.0" diff --git a/test/e2e/models/CodeServer.ts b/test/e2e/models/CodeServer.ts index f24500098..d5c00b96e 100644 --- a/test/e2e/models/CodeServer.ts +++ b/test/e2e/models/CodeServer.ts @@ -296,6 +296,16 @@ export class CodeServerPage { return visible } + /** + * Checks if the test extension loaded + */ + async waitForTestExtensionLoaded(): Promise { + const selector = "text=test extension loaded" + this.codeServer.logger.debug("Waiting for test extension to load...") + + await this.page.waitForSelector(selector) + } + /** * Focuses the integrated terminal by navigating through the command palette. *