@@ -3,6 +3,7 @@ import * as cp from "child_process"
3
3
import { promises as fs } from "fs"
4
4
import * as path from "path"
5
5
import { Page } from "playwright"
6
+ import util from "util"
6
7
import { logError , plural } from "../../../src/common/util"
7
8
import { onLine } from "../../../src/node/util"
8
9
import { PASSWORD , workspaceDir } from "../../utils/constants"
@@ -39,7 +40,11 @@ export class CodeServer {
39
40
private closed = false
40
41
private _workspaceDir : Promise < string > | undefined
41
42
42
- constructor ( name : string , private readonly codeServerArgs : string [ ] ) {
43
+ constructor (
44
+ name : string ,
45
+ private readonly codeServerArgs : string [ ] ,
46
+ private readonly codeServerEnv : NodeJS . ProcessEnv ,
47
+ ) {
43
48
this . logger = logger . named ( name )
44
49
}
45
50
@@ -96,6 +101,8 @@ export class CodeServer {
96
101
"node" ,
97
102
[
98
103
process . env . CODE_SERVER_TEST_ENTRY || "." ,
104
+ "--extensions-dir" ,
105
+ path . join ( dir , "extensions" ) ,
99
106
...this . codeServerArgs ,
100
107
// Using port zero will spawn on a random port.
101
108
"--bind-addr" ,
@@ -107,15 +114,14 @@ export class CodeServer {
107
114
path . join ( dir , "config.yaml" ) ,
108
115
"--user-data-dir" ,
109
116
dir ,
110
- "--extensions-dir" ,
111
- path . join ( __dirname , "../extensions" ) ,
112
117
// The last argument is the workspace to open.
113
118
dir ,
114
119
] ,
115
120
{
116
121
cwd : path . join ( __dirname , "../../.." ) ,
117
122
env : {
118
123
...process . env ,
124
+ ...this . codeServerEnv ,
119
125
PASSWORD ,
120
126
} ,
121
127
} ,
@@ -462,4 +468,24 @@ export class CodeServerPage {
462
468
await this . reloadUntilEditorIsReady ( )
463
469
}
464
470
}
471
+
472
+ /**
473
+ * Execute a command in t root of the instance's workspace directory.
474
+ */
475
+ async exec ( command : string ) : Promise < void > {
476
+ await util . promisify ( cp . exec ) ( command , {
477
+ cwd : await this . workspaceDir ,
478
+ } )
479
+ }
480
+
481
+ /**
482
+ * Install an extension by ID to the instance's temporary extension
483
+ * directory.
484
+ */
485
+ async installExtension ( id : string ) : Promise < void > {
486
+ const dir = path . join ( await this . workspaceDir , "extensions" )
487
+ await util . promisify ( cp . exec ) ( `node . --install-extension ${ id } --extensions-dir ${ dir } ` , {
488
+ cwd : path . join ( __dirname , "../../.." ) ,
489
+ } )
490
+ }
465
491
}
0 commit comments