Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a17cb36

Browse files
committedFeb 12, 2025··
Update test path matchers
1 parent 83c9c88 commit a17cb36

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed
 

‎test/e2e/routes.test.ts

+32-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
import { clean, getMaybeProxiedPathname } from "../utils/helpers"
22
import { describe, test, expect } from "./baseFixture"
33

4-
const routes = ["/", "/vscode", "/vscode/"]
4+
const routes = {
5+
"/": [
6+
/\.\/manifest.json/,
7+
/\.\/_static\//,
8+
/[a-z]+-[0-9a-z]+\/static\//,
9+
/http:\/\/localhost:[0-9]+\/[a-z]+-[0-9a-z]+\/static\//,
10+
],
11+
"/vscode": [
12+
/\.\/vscode\/manifest.json/,
13+
/\.\/_static\//,
14+
/vscode\/[a-z]+-[0-9a-z]+\/static\//,
15+
/http:\/\/localhost:[0-9]+\/vscode\/[a-z]+-[0-9a-z]+\/static\//,
16+
],
17+
"/vscode/": [
18+
/\.\/manifest.json/,
19+
/\.\/\.\.\/_static\//,
20+
/[a-z]+-[0-9a-z]+\/static\//,
21+
/http:\/\/localhost:[0-9]+\/vscode\/[a-z]+-[0-9a-z]+\/static\//,
22+
],
23+
}
524

625
describe("VS Code Routes", ["--disable-workspace-trust"], {}, async () => {
726
const testName = "vscode-routes-default"
@@ -10,29 +29,24 @@ describe("VS Code Routes", ["--disable-workspace-trust"], {}, async () => {
1029
})
1130

1231
test("should load all route variations", async ({ codeServerPage }) => {
13-
for (const route of routes) {
32+
for (const [route, matchers] of Object.entries(routes)) {
1433
await codeServerPage.navigate(route)
1534

1635
// Check there were no redirections
1736
const url = new URL(codeServerPage.page.url())
1837
const pathname = getMaybeProxiedPathname(url)
1938
expect(pathname).toBe(route)
2039

21-
// TODO@jsjoeio
22-
// now that we are in a proper browser instead of scraping the HTML we
23-
// could possibly intercept requests to make sure assets are loading from
24-
// the right spot.
25-
//
26-
// Check that page loaded from correct route
27-
const html = await codeServerPage.page.innerHTML("html")
28-
switch (route) {
29-
case "/":
30-
case "/vscode/":
31-
expect(html).toMatch(/src="\.\/[a-z]+-[0-9a-z]+\/static\//)
32-
break
33-
case "/vscode":
34-
expect(html).toMatch(/src="\.\/vscode\/[a-z]+-[0-9a-z]+\/static\//)
35-
break
40+
// Check that assets are pointing to the right spot. Some will be
41+
// relative, without a leading dot (VS Code's assets). Some will be
42+
// relative with a leading dot (our assets). Others will have been
43+
// resolved against the origin.
44+
const elements = await codeServerPage.page.locator("[src]").all()
45+
for (const element of elements) {
46+
const src = await element.getAttribute("src")
47+
if (src && !matchers.some((m) => m.test(src))) {
48+
throw new Error(`${src} did not match any validators for route ${route}`)
49+
}
3650
}
3751
}
3852
})
@@ -85,7 +99,7 @@ describe("VS Code Routes with no workspace or folder", ["--disable-workspace-tru
8599

86100
// If you visit again without query parameters it will re-attach them by
87101
// redirecting. It should always redirect to the same route.
88-
for (const route of routes) {
102+
for (const route of Object.keys(routes)) {
89103
await codeServerPage.navigate(route)
90104
const url = new URL(codeServerPage.page.url())
91105
const pathname = getMaybeProxiedPathname(url)

0 commit comments

Comments
 (0)
Please sign in to comment.