* Spawn a new code-server process with its own workspace and data * directories.
()
| 120 | * directories. |
| 121 | */ |
| 122 | private async spawn(): Promise<CodeServerProcess> { |
| 123 | const dir = await this.createWorkspace() |
| 124 | const args = await this.argsWithDefaults([ |
| 125 | "--auth", |
| 126 | "none", |
| 127 | // The workspace to open. |
| 128 | ...(this.args.includes("--ignore-last-opened") ? [] : [dir]), |
| 129 | ...this.args, |
| 130 | // Using port zero will spawn on a random port. |
| 131 | "--bind-addr", |
| 132 | "127.0.0.1:0", |
| 133 | ]) |
| 134 | return new Promise((resolve, reject) => { |
| 135 | this.logger.debug("spawning `node " + args.join(" ") + "`") |
| 136 | const proc = cp.spawn("node", args, { |
| 137 | cwd: path.join(__dirname, "../../.."), |
| 138 | env: { |
| 139 | ...process.env, |
| 140 | ...this.env, |
| 141 | // Prevent code-server from using the existing instance when running |
| 142 | // the e2e tests from an integrated terminal. |
| 143 | VSCODE_IPC_HOOK_CLI: "", |
| 144 | PASSWORD, |
| 145 | }, |
| 146 | }) |
| 147 | |
| 148 | const timer = idleTimer("Failed to extract address; did the format change?", reject) |
| 149 | |
| 150 | proc.on("error", (error) => { |
| 151 | this.logger.error(error.message) |
| 152 | timer.dispose() |
| 153 | reject(error) |
| 154 | }) |
| 155 | |
| 156 | proc.on("close", (code) => { |
| 157 | const error = new Error("code-server closed unexpectedly. Try running with LOG_LEVEL=debug to see more info.") |
| 158 | if (!this.closed) { |
| 159 | this.logger.error(error.message, field("code", code)) |
| 160 | } |
| 161 | timer.dispose() |
| 162 | reject(error) |
| 163 | }) |
| 164 | |
| 165 | // Tracks when the HTTP and session servers are ready. |
| 166 | let httpAddress: string | undefined |
| 167 | let sessionAddress: string | undefined |
| 168 | |
| 169 | let resolved = false |
| 170 | proc.stdout.setEncoding("utf8") |
| 171 | onLine(proc, (line) => { |
| 172 | // As long as we are actively getting input reset the timer. If we stop |
| 173 | // getting input and still have not found the addresses the timer will |
| 174 | // reject. |
| 175 | timer.reset() |
| 176 | |
| 177 | // Log the line without the timestamp. |
| 178 | this.logger.debug(line.replace(/\[.+\]/, "")) |
| 179 | if (resolved) { |
no test coverage detected