@@ -37,6 +37,7 @@ export class CodeServer {
37
37
private process : Promise < CodeServerProcess > | undefined
38
38
public readonly logger : Logger
39
39
private closed = false
40
+ private workspaceDir : Promise < string > | undefined
40
41
41
42
constructor ( name : string , private readonly codeServerArgs : string [ ] ) {
42
43
this . logger = logger . named ( name )
@@ -54,11 +55,18 @@ export class CodeServer {
54
55
return address
55
56
}
56
57
58
+ async dir ( ) : Promise < string > {
59
+ if ( ! this . workspaceDir ) {
60
+ this . workspaceDir = tmpdir ( workspaceDir )
61
+ }
62
+ return this . workspaceDir
63
+ }
64
+
57
65
/**
58
66
* Create a random workspace and seed it with settings.
59
67
*/
60
68
private async createWorkspace ( ) : Promise < string > {
61
- const dir = await tmpdir ( workspaceDir )
69
+ const dir = await this . dir ( )
62
70
await fs . mkdir ( path . join ( dir , "User" ) )
63
71
await fs . writeFile (
64
72
path . join ( dir , "User/settings.json" ) ,
@@ -190,6 +198,10 @@ export class CodeServerPage {
190
198
return this . codeServer . address ( )
191
199
}
192
200
201
+ dir ( ) {
202
+ return this . codeServer . dir ( )
203
+ }
204
+
193
205
/**
194
206
* Navigate to code-server.
195
207
*/
@@ -280,6 +292,23 @@ export class CodeServerPage {
280
292
await this . page . waitForSelector ( "textarea.xterm-helper-textarea" )
281
293
}
282
294
295
+ /**
296
+ * Open a file by using menus.
297
+ */
298
+ async openFile ( file : string ) {
299
+ const dir = await this . dir ( )
300
+ await this . navigateMenus ( [ "File" , "Open File" ] )
301
+ await this . navigatePicker ( [ path . basename ( file ) ] )
302
+ await this . waitForTab ( file )
303
+ }
304
+
305
+ /**
306
+ * Wait for a tab to open for the specified file.
307
+ */
308
+ async waitForTab ( file : string ) : Promise < void > {
309
+ return this . page . waitForSelector ( `.tab :text("${ path . basename ( file ) } ")` )
310
+ }
311
+
283
312
/**
284
313
* Navigate to the command palette via menus then execute a command by typing
285
314
* it then clicking the match from the results.
0 commit comments