Skip to content

Commit fbf2e19

Browse files
committed
Add customizable entry and workspace directory
1 parent c0fa92d commit fbf2e19

File tree

1 file changed

+34
-36
lines changed

1 file changed

+34
-36
lines changed

test/e2e/models/CodeServer.ts

+34-36
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as cp from "child_process"
33
import { promises as fs } from "fs"
44
import * as path from "path"
55
import { Page } from "playwright"
6-
import util from "util"
6+
import * as util from "util"
77
import { logError, plural } from "../../../src/common/util"
88
import { onLine } from "../../../src/node/util"
99
import { PASSWORD, workspaceDir } from "../../utils/constants"
@@ -38,12 +38,13 @@ export class CodeServer {
3838
private process: Promise<CodeServerProcess> | undefined
3939
public readonly logger: Logger
4040
private closed = false
41-
private _workspaceDir: Promise<string> | undefined
4241

4342
constructor(
4443
name: string,
45-
private readonly codeServerArgs: string[],
46-
private readonly codeServerEnv: NodeJS.ProcessEnv,
44+
private readonly args: string[],
45+
private readonly env: NodeJS.ProcessEnv,
46+
private readonly _workspaceDir: Promise<string> | string | undefined,
47+
private readonly entry = process.env.CODE_SERVER_TEST_ENTRY || ".",
4748
) {
4849
this.logger = logger.named(name)
4950
}
@@ -75,7 +76,7 @@ export class CodeServer {
7576
*/
7677
private async createWorkspace(): Promise<string> {
7778
const dir = await this.workspaceDir
78-
await fs.mkdir(path.join(dir, "User"))
79+
await fs.mkdir(path.join(dir, "User"), { recursive: true })
7980
await fs.writeFile(
8081
path.join(dir, "User/settings.json"),
8182
JSON.stringify({
@@ -96,36 +97,33 @@ export class CodeServer {
9697
const dir = await this.createWorkspace()
9798

9899
return new Promise((resolve, reject) => {
99-
this.logger.debug("spawning")
100-
const proc = cp.spawn(
101-
"node",
102-
[
103-
process.env.CODE_SERVER_TEST_ENTRY || ".",
104-
"--extensions-dir",
105-
path.join(dir, "extensions"),
106-
...this.codeServerArgs,
107-
// Using port zero will spawn on a random port.
108-
"--bind-addr",
109-
"127.0.0.1:0",
110-
// Setting the XDG variables would be easier and more thorough but the
111-
// modules we import ignores those variables for non-Linux operating
112-
// systems so use these flags instead.
113-
"--config",
114-
path.join(dir, "config.yaml"),
115-
"--user-data-dir",
116-
dir,
117-
// The last argument is the workspace to open.
118-
dir,
119-
],
120-
{
121-
cwd: path.join(__dirname, "../../.."),
122-
env: {
123-
...process.env,
124-
...this.codeServerEnv,
125-
PASSWORD,
126-
},
100+
const args = [
101+
this.entry,
102+
"--extensions-dir",
103+
path.join(dir, "extensions"),
104+
...this.args,
105+
// Using port zero will spawn on a random port.
106+
"--bind-addr",
107+
"127.0.0.1:0",
108+
// Setting the XDG variables would be easier and more thorough but the
109+
// modules we import ignores those variables for non-Linux operating
110+
// systems so use these flags instead.
111+
"--config",
112+
path.join(dir, "config.yaml"),
113+
"--user-data-dir",
114+
dir,
115+
// The last argument is the workspace to open.
116+
dir,
117+
]
118+
this.logger.debug("spawning `node " + args.join(" ") + "`")
119+
const proc = cp.spawn("node", args, {
120+
cwd: path.join(__dirname, "../../.."),
121+
env: {
122+
...process.env,
123+
...this.env,
124+
PASSWORD,
127125
},
128-
)
126+
})
129127

130128
const timer = idleTimer("Failed to extract address; did the format change?", reject)
131129

@@ -136,7 +134,7 @@ export class CodeServer {
136134
})
137135

138136
proc.on("close", (code) => {
139-
const error = new Error("closed unexpectedly")
137+
const error = new Error("code-server closed unexpectedly")
140138
if (!this.closed) {
141139
this.logger.error(error.message, field("code", code))
142140
}
@@ -153,7 +151,7 @@ export class CodeServer {
153151
timer.reset()
154152

155153
// Log the line without the timestamp.
156-
this.logger.trace(line.replace(/\[.+\]/, ""))
154+
this.logger.debug(line.replace(/\[.+\]/, ""))
157155
if (resolved) {
158156
return
159157
}

0 commit comments

Comments
 (0)