@@ -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,7 @@ 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 ( name : string , private readonly codeServerArgs : string [ ] , private readonly codeServerEnv : NodeJS . ProcessEnv ) {
43
44
this . logger = logger . named ( name )
44
45
}
45
46
@@ -96,6 +97,8 @@ export class CodeServer {
96
97
"node" ,
97
98
[
98
99
process . env . CODE_SERVER_TEST_ENTRY || "." ,
100
+ "--extensions-dir" ,
101
+ path . join ( dir , "extensions" ) ,
99
102
...this . codeServerArgs ,
100
103
// Using port zero will spawn on a random port.
101
104
"--bind-addr" ,
@@ -107,15 +110,14 @@ export class CodeServer {
107
110
path . join ( dir , "config.yaml" ) ,
108
111
"--user-data-dir" ,
109
112
dir ,
110
- "--extensions-dir" ,
111
- path . join ( __dirname , "../extensions" ) ,
112
113
// The last argument is the workspace to open.
113
114
dir ,
114
115
] ,
115
116
{
116
117
cwd : path . join ( __dirname , "../../.." ) ,
117
118
env : {
118
119
...process . env ,
120
+ ...this . codeServerEnv ,
119
121
PASSWORD ,
120
122
} ,
121
123
} ,
@@ -462,4 +464,24 @@ export class CodeServerPage {
462
464
await this . reloadUntilEditorIsReady ( )
463
465
}
464
466
}
467
+
468
+ /**
469
+ * Execute a command in t root of the instance's workspace directory.
470
+ */
471
+ async exec ( command : string ) : Promise < void > {
472
+ await util . promisify ( cp . exec ) ( command , {
473
+ cwd : await this . workspaceDir ,
474
+ } )
475
+ }
476
+
477
+ /**
478
+ * Install an extension by ID to the instance's temporary extension
479
+ * directory.
480
+ */
481
+ async installExtension ( id : string ) : Promise < void > {
482
+ const dir = path . join ( await this . workspaceDir , "extensions" )
483
+ await util . promisify ( cp . exec ) ( `node . --install-extension ${ id } --extensions-dir ${ dir } ` , {
484
+ cwd : path . join ( __dirname , "../../.." ) ,
485
+ } )
486
+ }
465
487
}
0 commit comments