1
1
import { promises as fs } from "fs"
2
- import { Response } from "node-fetch"
3
2
import * as path from "path"
4
3
import { clean , tmpdir } from "../../../utils/helpers"
5
4
import * as httpserver from "../../../utils/httpserver"
6
5
import * as integration from "../../../utils/integration"
7
6
8
- interface WorkbenchConfig {
9
- folderUri ?: {
10
- path : string
11
- }
12
- workspaceUri ?: {
13
- path : string
14
- }
15
- }
16
-
17
7
describe ( "vscode" , ( ) => {
18
8
let codeServer : httpserver . HttpServer | undefined
19
9
@@ -52,52 +42,25 @@ describe("vscode", () => {
52
42
}
53
43
} )
54
44
55
- /**
56
- * Get the workbench config from the provided response.
57
- */
58
- const getConfig = async ( resp : Response ) : Promise < WorkbenchConfig > => {
59
- expect ( resp . status ) . toBe ( 200 )
60
- const html = await resp . text ( )
61
- const match = html . match ( / < m e t a i d = " v s c o d e - w o r k b e n c h - w e b - c o n f i g u r a t i o n " d a t a - s e t t i n g s = " ( .+ ) " > / )
62
- if ( ! match || ! match [ 1 ] ) {
63
- throw new Error ( "Unable to find workbench configuration" )
64
- }
65
- const config = match [ 1 ] . replace ( / & q u o t ; / g, '"' )
66
- try {
67
- return JSON . parse ( config )
68
- } catch ( error ) {
69
- console . error ( "Failed to parse workbench configuration" , config )
70
- throw error
71
- }
72
- }
73
-
74
- it ( "should have no default folder or workspace" , async ( ) => {
75
- codeServer = await integration . setup ( [ "--auth=none" ] , "" )
76
-
77
- const config = await getConfig ( await codeServer . fetch ( "/" ) )
78
- expect ( config . folderUri ) . toBeUndefined ( )
79
- expect ( config . workspaceUri ) . toBeUndefined ( )
80
- } )
81
-
82
- it ( "should have a default folder" , async ( ) => {
83
- const defaultDir = await tmpdir ( testName )
84
- codeServer = await integration . setup ( [ "--auth=none" , defaultDir ] , "" )
45
+ it ( "should redirect to the passed in workspace" , async ( ) => {
46
+ const workspace = path . join ( await tmpdir ( testName ) , "test.code-workspace" )
47
+ await fs . writeFile ( workspace , "" )
48
+ codeServer = await integration . setup ( [ "--auth=none" , workspace ] , "" )
85
49
86
- // At first it will load the directory provided on the command line.
87
- const config = await getConfig ( await codeServer . fetch ( "/" ) )
88
- expect ( config . folderUri ?. path ) . toBe ( defaultDir )
89
- expect ( config . workspaceUri ) . toBeUndefined ( )
50
+ const resp = await codeServer . fetch ( "/" )
51
+ const url = new URL ( resp . url )
52
+ expect ( url . pathname ) . toBe ( "/" )
53
+ expect ( url . search ) . toBe ( `?workspace= ${ workspace } ` )
90
54
} )
91
55
92
- it ( "should have a default workspace" , async ( ) => {
93
- const defaultWorkspace = path . join ( await tmpdir ( testName ) , "test.code-workspace" )
94
- await fs . writeFile ( defaultWorkspace , "" )
95
- codeServer = await integration . setup ( [ "--auth=none" , defaultWorkspace ] , "" )
56
+ it ( "should redirect to the passed in directory" , async ( ) => {
57
+ const folder = await tmpdir ( testName )
58
+ codeServer = await integration . setup ( [ "--auth=none" , folder ] , "" )
96
59
97
- // At first it will load the workspace provided on the command line.
98
- const config = await getConfig ( await codeServer . fetch ( "/" ) )
99
- expect ( config . folderUri ) . toBeUndefined ( )
100
- expect ( config . workspaceUri ?. path ) . toBe ( defaultWorkspace )
60
+ const resp = await codeServer . fetch ( "/" )
61
+ const url = new URL ( resp . url )
62
+ expect ( url . pathname ) . toBe ( "/" )
63
+ expect ( url . search ) . toBe ( `?folder= ${ folder } ` )
101
64
} )
102
65
103
66
it ( "should redirect to last query folder/workspace" , async ( ) => {
@@ -136,7 +99,31 @@ describe("vscode", () => {
136
99
await resp . text ( )
137
100
} )
138
101
139
- it . only ( "should add the folder as a query param maintaining the slashes" , async ( ) => {
102
+ it ( "should add the workspace as a query param maintaining the slashes" , async ( ) => {
103
+ const workspace = path . join ( await tmpdir ( testName ) , "test.code-workspace" )
104
+ await fs . writeFile ( workspace , "" )
105
+ codeServer = await integration . setup ( [ "--auth=none" , workspace ] , "" )
106
+
107
+ let resp = await codeServer . fetch ( "/" , undefined )
108
+
109
+ expect ( resp . status ) . toBe ( 200 )
110
+ const url = new URL ( resp . url )
111
+ expect ( url . search ) . toBe ( `?workspace=${ workspace } ` )
112
+ await resp . text ( )
113
+ } )
114
+
115
+ it ( "should do nothing when nothing is passed in" , async ( ) => {
116
+ codeServer = await integration . setup ( [ "--auth=none" ] , "" )
117
+
118
+ let resp = await codeServer . fetch ( "/" , undefined )
119
+
120
+ expect ( resp . status ) . toBe ( 200 )
121
+ const url = new URL ( resp . url )
122
+ expect ( url . search ) . toBe ( "" )
123
+ await resp . text ( )
124
+ } )
125
+
126
+ it ( "should add the folder as a query param maintaining the slashes" , async ( ) => {
140
127
const folder = await tmpdir ( testName )
141
128
codeServer = await integration . setup ( [ "--auth=none" , folder ] , "" )
142
129
@@ -148,8 +135,6 @@ describe("vscode", () => {
148
135
await resp . text ( )
149
136
} )
150
137
151
- // TODO@jsjoeio - what about workspace?
152
-
153
138
it ( "should not redirect when last opened is ignored" , async ( ) => {
154
139
codeServer = await integration . setup ( [ "--auth=none" , "--ignore-last-opened" ] , "" )
155
140
0 commit comments