1
+ import { describe , test , expect } from "./baseFixture"
2
+ import { clean , tmpdir } from "../utils/helpers"
3
+ import * as path from "path"
4
+ import { promises as fs } from "fs"
5
+
6
+ const routes = [ "/" , "/vscode" , "/vscode/" ]
7
+
8
+ describe ( "VS Code Routes" , [ "--disable-workspace-trust" ] , { } , async ( ) => {
9
+ const testName = "vscode-routes-default"
10
+ test . beforeAll ( async ( ) => {
11
+ await clean ( testName )
12
+ } )
13
+
14
+ test ( "should load all route variations" , async ( { codeServerPage } ) => {
15
+ for ( const route of routes ) {
16
+ await codeServerPage . navigate ( route )
17
+
18
+ // Check there were no redirections
19
+ const url = new URL ( codeServerPage . page . url ( ) )
20
+ expect ( url . pathname ) . toBe ( route )
21
+
22
+ // TODO@jsjoeio
23
+ // now that we are in a proper browser instead of scraping the HTML we
24
+ // could possibly intercept requests to make sure assets are loading from
25
+ // the right spot.
26
+ //
27
+ // Check that page loaded from correct route
28
+ const html = await codeServerPage . page . innerHTML ( "html" )
29
+ switch ( route ) {
30
+ case "/" :
31
+ case "/vscode/" :
32
+ expect ( html ) . toMatch ( / s r c = " \. \/ [ a - z ] + - [ 0 - 9 a - z ] + \/ s t a t i c \/ / )
33
+ break
34
+ case "/vscode" :
35
+ expect ( html ) . toMatch ( / s r c = " \. \/ v s c o d e \/ [ a - z ] + - [ 0 - 9 a - z ] + \/ s t a t i c \/ / )
36
+ break
37
+ }
38
+ }
39
+ } )
40
+ } )
41
+
42
+ const CODE_WORKSPACE_DIR = process . env . CODE_WORKSPACE_DIR || ""
43
+ describe ( "VS Code Routes with code-workspace" , [ "--disable-workspace-trust" , CODE_WORKSPACE_DIR ] , { } , async ( ) => {
44
+ test ( "should redirect to the passed in workspace using human-readable query" , async ( { codeServerPage } ) => {
45
+ const url = new URL ( codeServerPage . page . url ( ) )
46
+ expect ( url . pathname ) . toBe ( "/" )
47
+ expect ( url . search ) . toBe ( `?workspace=${ CODE_WORKSPACE_DIR } ` )
48
+ } )
49
+ } )
50
+
51
+ const CODE_FOLDER_DIR = process . env . CODE_FOLDER_DIR || ""
52
+ describe ( "VS Code Routes with code-workspace" , [ "--disable-workspace-trust" , CODE_FOLDER_DIR ] , { } , async ( ) => {
53
+ test ( "should redirect to the passed in folder using human-readable query" , async ( { codeServerPage } ) => {
54
+ const url = new URL ( codeServerPage . page . url ( ) )
55
+ expect ( url . pathname ) . toBe ( "/" )
56
+ expect ( url . search ) . toBe ( `?folder=${ CODE_FOLDER_DIR } ` )
57
+ } )
58
+ } )
59
+
60
+ describe (
61
+ "VS Code Routes with ignore-last-opened" ,
62
+ [ "--disable-workspace-trust" , "--ignore-last-opened" ] ,
63
+ { } ,
64
+ async ( ) => {
65
+ test ( "should not redirect" , async ( { codeServerPage } ) => {
66
+ const folder = process . env . CODE_FOLDER_DIR
67
+
68
+ await codeServerPage . navigate ( `/` )
69
+ await codeServerPage . navigate ( `/?folder=${ folder } ` )
70
+ await codeServerPage . navigate ( `/` )
71
+
72
+ const url = new URL ( codeServerPage . page . url ( ) )
73
+ expect ( url . pathname ) . toBe ( "/" )
74
+ expect ( url . search ) . toBe ( "" )
75
+ } )
76
+ } ,
77
+ )
78
+
79
+ describe (
80
+ "VS Code Routes with no workspace or folder" ,
81
+ [ "--disable-workspace-trust" ] ,
82
+ { } ,
83
+ async ( ) => {
84
+ test ( "should redirect to last query folder/workspace" , async ( { codeServerPage } ) => {
85
+ const folder = process . env . CODE_FOLDER_DIR
86
+ const workspace = process . env . CODE_WORKSPACE_DIR
87
+ await codeServerPage . navigate ( `/?folder=${ folder } &workspace=${ workspace } ` )
88
+
89
+ // If you visit again without query parameters it will re-attach them by
90
+ // redirecting. It should always redirect to the same route.
91
+ for ( const route of routes ) {
92
+ await codeServerPage . navigate ( route )
93
+ const url = new URL ( codeServerPage . page . url ( ) )
94
+ expect ( url . pathname ) . toBe ( route )
95
+ expect ( url . search ) . toBe ( `?folder=${ folder } &workspace=${ workspace } ` )
96
+ }
97
+ } )
98
+ } ,
99
+ )
100
+
101
+ describe (
102
+ "VS Code Routes with no workspace or folder" ,
103
+ [ "--disable-workspace-trust" ] ,
104
+ { } ,
105
+ async ( ) => {
106
+ test ( "should not redirect if ew passed in" , async ( { codeServerPage } ) => {
107
+ const folder = process . env . CODE_FOLDER_DIR
108
+ const workspace = process . env . CODE_WORKSPACE_DIR
109
+ await codeServerPage . navigate ( `/?folder=${ folder } &workspace=${ workspace } ` )
110
+
111
+ // Closing the folder should stop the redirecting.
112
+ await codeServerPage . navigate ( "/?ew=true" )
113
+ let url = new URL ( codeServerPage . page . url ( ) )
114
+ expect ( url . pathname ) . toBe ( "/" )
115
+ expect ( url . search ) . toBe ( "?ew=true" )
116
+ } )
117
+ } ,
118
+ )
0 commit comments