Skip to content

Commit 7ecbd21

Browse files
committed
Update test path matchers
1 parent 83c9c88 commit 7ecbd21

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

test/e2e/routes.test.ts

+31-17
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+
/src="\.\/manifest.json"/,
7+
/src="\.\/_static\//,
8+
/src="[a-z]+-[0-9a-z]+\/static\//,
9+
/src="http:\/\/localhost:[0-9]+\/[a-z]+-[0-9a-z]+\/static\//,
10+
],
11+
"/vscode": [
12+
/src="\.\/manifest.json"/,
13+
/src="\.\/\.\.\/_static\//,
14+
/src="[a-z]+-[0-9a-z]+\/static\//,
15+
/src="http:\/\/localhost:[0-9]+\/vscode\/[a-z]+-[0-9a-z]+\/static\//,
16+
],
17+
"/vscode/": [
18+
/src="\.\/_static\//,
19+
/src="\.\/vscode\/manifest.json"/,
20+
/src="vscode\/[a-z]+-[0-9a-z]+\/static\//,
21+
/src="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 (!matchers.some((m) => m.test(src))) {
48+
throw new Error(`${src} did not match any validators for route ${route}`)
49+
}
3650
}
3751
}
3852
})

0 commit comments

Comments
 (0)