Skip to content

Commit c4d6479

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

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

test/e2e/routes.test.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,35 @@ describe("VS Code Routes", ["--disable-workspace-trust"], {}, async () => {
1818
const pathname = getMaybeProxiedPathname(url)
1919
expect(pathname).toBe(route)
2020

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")
21+
// Check that assets are pointing to the right spot. Some will be
22+
// relative, without a leading dot (VS Code's assets). Some will be
23+
// relative with a leading dot (our assets). Others will have been
24+
// resolved against the origin.
25+
const matchers: string[] = []
2826
switch (route) {
2927
case "/":
28+
matchers.push(/src="\.\/manifest.json"/)
29+
matchers.push(/src="\.\/_static\//)
30+
matchers.push(/src="[a-z]+-[0-9a-z]+\/static\//)
31+
matchers.push(/src="http:\/\/localhost:[0-9]+\/[a-z]+-[0-9a-z]+\/static\//)
3032
case "/vscode/":
31-
expect(html).toMatch(/src="\.\/[a-z]+-[0-9a-z]+\/static\//)
33+
matchers.push(/src="\.\/manifest.json"/)
34+
matchers.push(/src="\.\/\.\.\/_static\//)
35+
matchers.push(/src="[a-z]+-[0-9a-z]+\/static\//)
36+
matchers.push(/src="http:\/\/localhost:[0-9]+\/vscode\/[a-z]+-[0-9a-z]+\/static\//)
3237
break
3338
case "/vscode":
34-
expect(html).toMatch(/src="\.\/vscode\/[a-z]+-[0-9a-z]+\/static\//)
39+
matchers.push(/src="\.\/_static\//)
40+
matchers.push(/src="\.\/vscode\/manifest.json"/)
41+
matchers.push(/src="vscode\/[a-z]+-[0-9a-z]+\/static\//)
42+
matchers.push(/src="http:\/\/localhost:[0-9]+\/vscode\/[a-z]+-[0-9a-z]+\/static\//)
3543
break
3644
}
45+
const elements = await codeServerPage.page.locator("[src]").all()
46+
for (const element of elements) {
47+
const src = await element.getAttribute("src")
48+
expect(matchers.some((m) => m.test(src))).toBeTruthy()
49+
}
3750
}
3851
})
3952
})

0 commit comments

Comments
 (0)