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 c4d6479
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions test/e2e/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,35 @@ 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")
// 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 matchers: string[] = []
switch (route) {
case "/":
matchers.push(/src="\.\/manifest.json"/)
matchers.push(/src="\.\/_static\//)
matchers.push(/src="[a-z]+-[0-9a-z]+\/static\//)
matchers.push(/src="http:\/\/localhost:[0-9]+\/[a-z]+-[0-9a-z]+\/static\//)
case "/vscode/":

Check failure on line 32 in test/e2e/routes.test.ts

View workflow job for this annotation

GitHub Actions / Lint TypeScript files

Expected a 'break' statement before 'case'
expect(html).toMatch(/src="\.\/[a-z]+-[0-9a-z]+\/static\//)
matchers.push(/src="\.\/manifest.json"/)
matchers.push(/src="\.\/\.\.\/_static\//)
matchers.push(/src="[a-z]+-[0-9a-z]+\/static\//)
matchers.push(/src="http:\/\/localhost:[0-9]+\/vscode\/[a-z]+-[0-9a-z]+\/static\//)
break
case "/vscode":
expect(html).toMatch(/src="\.\/vscode\/[a-z]+-[0-9a-z]+\/static\//)
matchers.push(/src="\.\/_static\//)
matchers.push(/src="\.\/vscode\/manifest.json"/)
matchers.push(/src="vscode\/[a-z]+-[0-9a-z]+\/static\//)
matchers.push(/src="http:\/\/localhost:[0-9]+\/vscode\/[a-z]+-[0-9a-z]+\/static\//)
break
}
const elements = await codeServerPage.page.locator("[src]").all()
for (const element of elements) {
const src = await element.getAttribute("src")
expect(matchers.some((m) => m.test(src))).toBeTruthy()
}
}
})
})
Expand Down

0 comments on commit c4d6479

Please # to comment.