11import { clean , getMaybeProxiedPathname } from "../utils/helpers"
22import { describe , test , expect } from "./baseFixture"
33
4- const routes = [ "/" , "/vscode" , "/vscode/" ]
4+ const routes = {
5+ "/" : [
6+ / \. \/ m a n i f e s t .j s o n / ,
7+ / \. \/ _ s t a t i c \/ / ,
8+ / [ a - z ] + - [ 0 - 9 a - z ] + \/ s t a t i c \/ / ,
9+ / h t t p : \/ \/ l o c a l h o s t : [ 0 - 9 ] + \/ [ a - z ] + - [ 0 - 9 a - z ] + \/ s t a t i c \/ / ,
10+ ] ,
11+ "/vscode" : [
12+ / \. \/ v s c o d e \/ m a n i f e s t .j s o n / ,
13+ / \. \/ _ s t a t i c \/ / ,
14+ / v s c o d e \/ [ a - z ] + - [ 0 - 9 a - z ] + \/ s t a t i c \/ / ,
15+ / h t t p : \/ \/ l o c a l h o s t : [ 0 - 9 ] + \/ v s c o d e \/ [ a - z ] + - [ 0 - 9 a - z ] + \/ s t a t i c \/ / ,
16+ ] ,
17+ "/vscode/" : [
18+ / \. \/ m a n i f e s t .j s o n / ,
19+ / \. \/ \. \. \/ _ s t a t i c \/ / ,
20+ / [ a - z ] + - [ 0 - 9 a - z ] + \/ s t a t i c \/ / ,
21+ / h t t p : \/ \/ l o c a l h o s t : [ 0 - 9 ] + \/ v s c o d e \/ [ a - z ] + - [ 0 - 9 a - z ] + \/ s t a t i c \/ / ,
22+ ] ,
23+ }
524
625describe ( "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 ( / s r c = " \. \/ [ a - z ] + - [ 0 - 9 a - z ] + \/ s t a t i c \/ / )
32- break
33- case "/vscode" :
34- expect ( html ) . toMatch ( / s r c = " \. \/ v s c o d e \/ [ a - z ] + - [ 0 - 9 a - z ] + \/ s t a t i c \/ / )
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