@@ -4,10 +4,10 @@ import { promises as fs } from "fs"
44import * as path from "path"
55import { Page } from "playwright"
66import * as util from "util"
7- import { logError , plural } from "../../../src/common/util"
7+ import { logError , normalize , plural } from "../../../src/common/util"
88import { onLine } from "../../../src/node/util"
99import { PASSWORD , workspaceDir } from "../../utils/constants"
10- import { idleTimer , tmpdir } from "../../utils/helpers"
10+ import { getMaybeProxiedCodeServer , idleTimer , tmpdir } from "../../utils/helpers"
1111
1212interface CodeServerProcess {
1313 process : cp . ChildProcess
@@ -58,6 +58,15 @@ export class CodeServer {
5858 this . process = this . spawn ( )
5959 }
6060 const { address } = await this . process
61+
62+ // NOTE@jsjoeio - when enabled, we assume code-server is running
63+ // via a reverse proxy with something like Caddy
64+ // and being accessed at host/port i.e. localhost:8000/1337
65+ // if (process.env.USE_PROXY && process.env.USE_PROXY === "1") {
66+ // const uri = new URL(address)
67+ // return `http://${uri.hostname}:8000/${uri.port}/ide/`
68+ // }
69+
6170 return address
6271 }
6372
@@ -104,6 +113,8 @@ export class CodeServer {
104113 this . entry ,
105114 "--extensions-dir" ,
106115 path . join ( dir , "extensions" ) ,
116+ "--auth" ,
117+ "none" ,
107118 ...this . args ,
108119 // Using port zero will spawn on a random port.
109120 "--bind-addr" ,
@@ -124,6 +135,10 @@ export class CodeServer {
124135 env : {
125136 ...process . env ,
126137 ...this . env ,
138+ // Set to empty string to prevent code-server from
139+ // using the existing instance when running the e2e tests
140+ // from an integrated terminal.
141+ VSCODE_IPC_HOOK_CLI : "" ,
127142 PASSWORD ,
128143 } ,
129144 } )
@@ -183,6 +198,13 @@ export class CodeServer {
183198 proc . kill ( )
184199 }
185200 }
201+
202+ /**
203+ * Whether or not authentication is enabled.
204+ */
205+ authEnabled ( ) : boolean {
206+ return this . args . includes ( "password" )
207+ }
186208}
187209
188210/**
@@ -195,11 +217,7 @@ export class CodeServer {
195217export class CodeServerPage {
196218 private readonly editorSelector = "div.monaco-workbench"
197219
198- constructor (
199- private readonly codeServer : CodeServer ,
200- public readonly page : Page ,
201- private readonly authenticated : boolean ,
202- ) {
220+ constructor ( private readonly codeServer : CodeServer , public readonly page : Page ) {
203221 this . page . on ( "console" , ( message ) => {
204222 this . codeServer . logger . debug ( message . text ( ) )
205223 } )
@@ -224,12 +242,16 @@ export class CodeServerPage {
224242 * editor to become available.
225243 */
226244 async navigate ( endpoint = "/" ) {
227- const to = new URL ( endpoint , await this . codeServer . address ( ) )
245+ const address = await getMaybeProxiedCodeServer ( this . codeServer )
246+ const noramlizedUrl = normalize ( address + endpoint , true )
247+ const to = new URL ( noramlizedUrl )
248+
249+ this . codeServer . logger . info ( `navigating to ${ to } ` )
228250 await this . page . goto ( to . toString ( ) , { waitUntil : "networkidle" } )
229251
230- // Only reload editor if authenticated . Otherwise we'll get stuck
252+ // Only reload editor if auth is not enabled . Otherwise we'll get stuck
231253 // reloading the login page.
232- if ( this . authenticated ) {
254+ if ( ! this . codeServer . authEnabled ( ) ) {
233255 await this . reloadUntilEditorIsReady ( )
234256 }
235257 }
0 commit comments