Skip to content

Commit

Permalink
Update test path matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
code-asher committed Feb 12, 2025
1 parent 83c9c88 commit c86cb8c
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions test/e2e/routes.test.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -10,29 +29,24 @@ 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
const url = new URL(codeServerPage.page.url())
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}`)
}
}
}
})
Expand Down

0 comments on commit c86cb8c

Please sign in to comment.