From c86cb8cf7c9e85767a7ccc3abc8b013faa8e953a Mon Sep 17 00:00:00 2001 From: Asher Date: Wed, 12 Feb 2025 12:07:17 -0900 Subject: [PATCH] Update test path matchers --- test/e2e/routes.test.ts | 48 ++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/test/e2e/routes.test.ts b/test/e2e/routes.test.ts index 2ac87d0026a9..ecf53027beaf 100644 --- a/test/e2e/routes.test.ts +++ b/test/e2e/routes.test.ts @@ -1,7 +1,26 @@ import { clean, getMaybeProxiedPathname } from "../utils/helpers" import { describe, test, expect } from "./baseFixture" -const routes = ["/", "/vscode", "/vscode/"] +const routes = { + "/": [ + /\.\/manifest.json/, + /\.\/_static\//, + /[a-z]+-[0-9a-z]+\/static\//, + /http:\/\/localhost:[0-9]+\/[a-z]+-[0-9a-z]+\/static\//, + ], + "/vscode": [ + /\.\/manifest.json/, + /\.\/\.\.\/_static\//, + /[a-z]+-[0-9a-z]+\/static\//, + /http:\/\/localhost:[0-9]+\/vscode\/[a-z]+-[0-9a-z]+\/static\//, + ], + "/vscode/": [ + /\.\/vscode\/manifest.json/, + /\.\/_static\//, + /vscode\/[a-z]+-[0-9a-z]+\/static\//, + /http:\/\/localhost:[0-9]+\/vscode\/[a-z]+-[0-9a-z]+\/static\//, + ], +} describe("VS Code Routes", ["--disable-workspace-trust"], {}, async () => { const testName = "vscode-routes-default" @@ -10,7 +29,7 @@ describe("VS Code Routes", ["--disable-workspace-trust"], {}, async () => { }) test("should load all route variations", async ({ codeServerPage }) => { - for (const route of routes) { + for (const [route, matchers] of Object.entries(routes)) { await codeServerPage.navigate(route) // Check there were no redirections @@ -18,21 +37,16 @@ describe("VS Code Routes", ["--disable-workspace-trust"], {}, async () => { const pathname = getMaybeProxiedPathname(url) expect(pathname).toBe(route) - // TODO@jsjoeio - // now that we are in a proper browser instead of scraping the HTML we - // could possibly intercept requests to make sure assets are loading from - // the right spot. - // - // Check that page loaded from correct route - const html = await codeServerPage.page.innerHTML("html") - switch (route) { - case "/": - case "/vscode/": - expect(html).toMatch(/src="\.\/[a-z]+-[0-9a-z]+\/static\//) - break - case "/vscode": - expect(html).toMatch(/src="\.\/vscode\/[a-z]+-[0-9a-z]+\/static\//) - break + // Check that assets are pointing to the right spot. Some will be + // relative, without a leading dot (VS Code's assets). Some will be + // relative with a leading dot (our assets). Others will have been + // resolved against the origin. + const elements = await codeServerPage.page.locator("[src]").all() + for (const element of elements) { + const src = await element.getAttribute("src") + if (src && !matchers.some((m) => m.test(src))) { + throw new Error(`${src} did not match any validators for route ${route}`) + } } } })