1
1
import { clean , getMaybeProxiedPathname } from "../utils/helpers"
2
2
import { describe , test , expect } from "./baseFixture"
3
3
4
- const routes = [ "/" , "/vscode" , "/vscode/" ]
4
+ const routes = {
5
+ "/" : [
6
+ / s r c = " \. \/ m a n i f e s t .j s o n " / ,
7
+ / s r c = " \. \/ _ s t a t i c \/ / ,
8
+ / s r c = " [ a - z ] + - [ 0 - 9 a - z ] + \/ s t a t i c \/ / ,
9
+ / s r c = " 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
+ / s r c = " \. \/ m a n i f e s t .j s o n " / ,
13
+ / s r c = " \. \/ \. \. \/ _ s t a t i c \/ / ,
14
+ / s r c = " [ a - z ] + - [ 0 - 9 a - z ] + \/ s t a t i c \/ / ,
15
+ / s r c = " 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
+ / s r c = " \. \/ _ s t a t i c \/ / ,
19
+ / s r c = " \. \/ v s c o d e \/ m a n i f e s t .j s o n " / ,
20
+ / s r c = " v s c o d e \/ [ a - z ] + - [ 0 - 9 a - z ] + \/ s t a t i c \/ / ,
21
+ / s r c = " 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
+ }
5
24
6
25
describe ( "VS Code Routes" , [ "--disable-workspace-trust" ] , { } , async ( ) => {
7
26
const testName = "vscode-routes-default"
@@ -10,29 +29,24 @@ describe("VS Code Routes", ["--disable-workspace-trust"], {}, async () => {
10
29
} )
11
30
12
31
test ( "should load all route variations" , async ( { codeServerPage } ) => {
13
- for ( const route of routes ) {
32
+ for ( const [ route , matchers ] of Object . entries ( routes ) ) {
14
33
await codeServerPage . navigate ( route )
15
34
16
35
// Check there were no redirections
17
36
const url = new URL ( codeServerPage . page . url ( ) )
18
37
const pathname = getMaybeProxiedPathname ( url )
19
38
expect ( pathname ) . toBe ( route )
20
39
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 ( ! matchers . some ( ( m ) => m . test ( src ) ) ) {
48
+ throw new Error ( `${ src } did not match any validators for route ${ route } ` )
49
+ }
36
50
}
37
51
}
38
52
} )
0 commit comments