@@ -20,14 +20,14 @@ class Context {
20
20
public canceled ( ) : boolean {
21
21
return this . _canceled
22
22
}
23
- public done ( ) : void {
24
- this . _done = true
23
+ public finished ( ) : boolean {
24
+ return this . _done
25
25
}
26
26
public cancel ( ) : void {
27
27
this . _canceled = true
28
28
}
29
- public finish ( ) : boolean {
30
- return this . _done
29
+ public finish ( ) : void {
30
+ this . _done = true
31
31
}
32
32
}
33
33
@@ -43,7 +43,7 @@ export class CodeServer {
43
43
name : string ,
44
44
private readonly args : string [ ] ,
45
45
private readonly env : NodeJS . ProcessEnv ,
46
- private readonly _workspaceDir : Promise < string > | string | undefined ,
46
+ private _workspaceDir : Promise < string > | string | undefined ,
47
47
private readonly entry = process . env . CODE_SERVER_TEST_ENTRY || "." ,
48
48
) {
49
49
this . logger = logger . named ( name )
@@ -64,7 +64,7 @@ export class CodeServer {
64
64
/**
65
65
* The workspace directory code-server opens with.
66
66
*/
67
- get workspaceDir ( ) : Promise < string > {
67
+ get workspaceDir ( ) : Promise < string > | string {
68
68
if ( ! this . _workspaceDir ) {
69
69
this . _workspaceDir = tmpdir ( workspaceDir )
70
70
}
@@ -198,7 +198,7 @@ export class CodeServerPage {
198
198
private readonly authenticated : boolean ,
199
199
) {
200
200
this . page . on ( "console" , ( message ) => {
201
- this . codeServer . logger . debug ( message )
201
+ this . codeServer . logger . debug ( message . text ( ) )
202
202
} )
203
203
this . page . on ( "pageerror" , ( error ) => {
204
204
logError ( this . codeServer . logger , "page" , error )
@@ -241,22 +241,21 @@ export class CodeServerPage {
241
241
this . codeServer . logger . debug ( "Waiting for editor to be ready..." )
242
242
243
243
const editorIsVisible = await this . isEditorVisible ( )
244
- const editorIsConnected = await this . isConnected ( )
245
244
let reloadCount = 0
246
245
247
246
// Occassionally code-server timeouts in Firefox
248
247
// we're not sure why
249
248
// but usually a reload or two fixes it
250
249
// TODO@jsjoeio @oxy look into Firefox reconnection/timeout issues
251
- while ( ! editorIsVisible && ! editorIsConnected ) {
250
+ while ( ! editorIsVisible ) {
252
251
// When a reload happens, we want to wait for all resources to be
253
252
// loaded completely. Hence why we use that instead of DOMContentLoaded
254
253
// Read more: https://thisthat.dev/dom-content-loaded-vs-load/
255
254
await this . page . waitForLoadState ( "load" )
256
255
// Give it an extra second just in case it's feeling extra slow
257
256
await this . page . waitForTimeout ( 1000 )
258
257
reloadCount += 1
259
- if ( ( await this . isEditorVisible ( ) ) && ( await this . isConnected ( ) ) ) {
258
+ if ( await this . isEditorVisible ( ) ) {
260
259
this . codeServer . logger . debug ( `editor became ready after ${ reloadCount } reloads` )
261
260
break
262
261
}
@@ -280,23 +279,6 @@ export class CodeServerPage {
280
279
return visible
281
280
}
282
281
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
-
300
282
/**
301
283
* Focuses Integrated Terminal
302
284
* by using "Terminal: Focus Terminal"
@@ -326,13 +308,13 @@ export class CodeServerPage {
326
308
* Wait for a tab to open for the specified file.
327
309
*/
328
310
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 ) } ")` )
330
312
}
331
313
332
314
/**
333
315
* See if the specified tab is open.
334
316
*/
335
- async tabIsVisible ( file : string ) : Promise < void > {
317
+ async tabIsVisible ( file : string ) : Promise < boolean > {
336
318
return this . page . isVisible ( `.tab :text("${ path . basename ( file ) } ")` )
337
319
}
338
320
@@ -368,8 +350,8 @@ export class CodeServerPage {
368
350
try {
369
351
await this . page . waitForSelector ( `${ selector } :not(:focus-within)` )
370
352
} 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 } ` )
373
355
}
374
356
}
375
357
return false
@@ -423,7 +405,7 @@ export class CodeServerPage {
423
405
return false
424
406
}
425
407
} catch ( error ) {
426
- logger . debug ( `navigation: ${ error . message || error } ` )
408
+ logger . debug ( `navigation: ${ ( error as any ) . message || error } ` )
427
409
return false
428
410
}
429
411
}
@@ -436,7 +418,7 @@ export class CodeServerPage {
436
418
// time we lose focus or there is an error.
437
419
let attempts = 1
438
420
let context = new Context ( )
439
- while ( ! ( await Promise . race ( [ openThenWaitClose ( ) , navigate ( context ) ] ) ) ) {
421
+ while ( ! ( await Promise . race ( [ openThenWaitClose ( context ) , navigate ( context ) ] ) ) ) {
440
422
++ attempts
441
423
logger . debug ( "closed, retrying (${attempt}/∞)" )
442
424
context . cancel ( )
0 commit comments