@@ -20,14 +20,14 @@ class Context {
2020 public canceled ( ) : boolean {
2121 return this . _canceled
2222 }
23- public done ( ) : void {
24- this . _done = true
23+ public finished ( ) : boolean {
24+ return this . _done
2525 }
2626 public cancel ( ) : void {
2727 this . _canceled = true
2828 }
29- public finish ( ) : boolean {
30- return this . _done
29+ public finish ( ) : void {
30+ this . _done = true
3131 }
3232}
3333
@@ -43,7 +43,7 @@ export class CodeServer {
4343 name : string ,
4444 private readonly args : string [ ] ,
4545 private readonly env : NodeJS . ProcessEnv ,
46- private readonly _workspaceDir : Promise < string > | string | undefined ,
46+ private _workspaceDir : Promise < string > | string | undefined ,
4747 private readonly entry = process . env . CODE_SERVER_TEST_ENTRY || "." ,
4848 ) {
4949 this . logger = logger . named ( name )
@@ -64,7 +64,7 @@ export class CodeServer {
6464 /**
6565 * The workspace directory code-server opens with.
6666 */
67- get workspaceDir ( ) : Promise < string > {
67+ get workspaceDir ( ) : Promise < string > | string {
6868 if ( ! this . _workspaceDir ) {
6969 this . _workspaceDir = tmpdir ( workspaceDir )
7070 }
@@ -198,7 +198,7 @@ export class CodeServerPage {
198198 private readonly authenticated : boolean ,
199199 ) {
200200 this . page . on ( "console" , ( message ) => {
201- this . codeServer . logger . debug ( message )
201+ this . codeServer . logger . debug ( message . text ( ) )
202202 } )
203203 this . page . on ( "pageerror" , ( error ) => {
204204 logError ( this . codeServer . logger , "page" , error )
@@ -241,22 +241,21 @@ export class CodeServerPage {
241241 this . codeServer . logger . debug ( "Waiting for editor to be ready..." )
242242
243243 const editorIsVisible = await this . isEditorVisible ( )
244- const editorIsConnected = await this . isConnected ( )
245244 let reloadCount = 0
246245
247246 // Occassionally code-server timeouts in Firefox
248247 // we're not sure why
249248 // but usually a reload or two fixes it
250249 // TODO@jsjoeio @oxy look into Firefox reconnection/timeout issues
251- while ( ! editorIsVisible && ! editorIsConnected ) {
250+ while ( ! editorIsVisible ) {
252251 // When a reload happens, we want to wait for all resources to be
253252 // loaded completely. Hence why we use that instead of DOMContentLoaded
254253 // Read more: https://thisthat.dev/dom-content-loaded-vs-load/
255254 await this . page . waitForLoadState ( "load" )
256255 // Give it an extra second just in case it's feeling extra slow
257256 await this . page . waitForTimeout ( 1000 )
258257 reloadCount += 1
259- if ( ( await this . isEditorVisible ( ) ) && ( await this . isConnected ( ) ) ) {
258+ if ( await this . isEditorVisible ( ) ) {
260259 this . codeServer . logger . debug ( `editor became ready after ${ reloadCount } reloads` )
261260 break
262261 }
@@ -280,23 +279,6 @@ export class CodeServerPage {
280279 return visible
281280 }
282281
283- /**
284- * Checks if the editor is visible
285- */
286- async isConnected ( ) {
287- this . codeServer . logger . debug ( "Waiting for network idle..." )
288-
289- await this . page . waitForLoadState ( "networkidle" )
290-
291- const host = new URL ( await this . codeServer . address ( ) ) . host
292- // NOTE: This seems to be pretty brittle between version changes.
293- const hostSelector = `[aria-label="remote ${ host } "]`
294- this . codeServer . logger . debug ( `Waiting selector: ${ hostSelector } ` )
295- await this . page . waitForSelector ( hostSelector )
296-
297- return await this . page . isVisible ( hostSelector )
298- }
299-
300282 /**
301283 * Focuses Integrated Terminal
302284 * by using "Terminal: Focus Terminal"
@@ -326,13 +308,13 @@ export class CodeServerPage {
326308 * Wait for a tab to open for the specified file.
327309 */
328310 async waitForTab ( file : string ) : Promise < void > {
329- return this . page . waitForSelector ( `.tab :text("${ path . basename ( file ) } ")` )
311+ await this . page . waitForSelector ( `.tab :text("${ path . basename ( file ) } ")` )
330312 }
331313
332314 /**
333315 * See if the specified tab is open.
334316 */
335- async tabIsVisible ( file : string ) : Promise < void > {
317+ async tabIsVisible ( file : string ) : Promise < boolean > {
336318 return this . page . isVisible ( `.tab :text("${ path . basename ( file ) } ")` )
337319 }
338320
@@ -368,8 +350,8 @@ export class CodeServerPage {
368350 try {
369351 await this . page . waitForSelector ( `${ selector } :not(:focus-within)` )
370352 } catch ( error ) {
371- if ( ! ctx . done ( ) ) {
372- this . codeServer . logger . debug ( `${ selector } navigation: ${ error . message || error } ` )
353+ if ( ! ctx . finished ( ) ) {
354+ this . codeServer . logger . debug ( `${ selector } navigation: ${ ( error as any ) . message || error } ` )
373355 }
374356 }
375357 return false
@@ -423,7 +405,7 @@ export class CodeServerPage {
423405 return false
424406 }
425407 } catch ( error ) {
426- logger . debug ( `navigation: ${ error . message || error } ` )
408+ logger . debug ( `navigation: ${ ( error as any ) . message || error } ` )
427409 return false
428410 }
429411 }
@@ -436,7 +418,7 @@ export class CodeServerPage {
436418 // time we lose focus or there is an error.
437419 let attempts = 1
438420 let context = new Context ( )
439- while ( ! ( await Promise . race ( [ openThenWaitClose ( ) , navigate ( context ) ] ) ) ) {
421+ while ( ! ( await Promise . race ( [ openThenWaitClose ( context ) , navigate ( context ) ] ) ) ) {
440422 ++ attempts
441423 logger . debug ( "closed, retrying (${attempt}/∞)" )
442424 context . cancel ( )
0 commit comments