@@ -25,7 +25,7 @@ export class Sessions {
25
25
private quickPick : SessionQuickPick ;
26
26
private trashButton : ( sessionId : string ) => Locator ;
27
27
private newConsoleButton : Locator ;
28
- private restartButton : Locator ;
28
+ restartButton : Locator ;
29
29
private shutDownButton : Locator ;
30
30
sessionTabs : Locator ;
31
31
currentSessionTab : Locator ;
@@ -211,13 +211,28 @@ export class Sessions {
211
211
async deleteDisconnectedSessions ( ) {
212
212
await test . step ( 'Delete all disconnected sessions' , async ( ) => {
213
213
const sessionIds = await this . getAllSessionIds ( ) ;
214
+ const disconnectedSessions : string [ ] = [ ] ;
214
215
216
+ // Collect all disconnected session IDs
215
217
for ( const sessionId of sessionIds ) {
216
218
const status = await this . getStatus ( sessionId ) ;
217
219
if ( status === 'disconnected' ) {
218
- await this . delete ( sessionId ) ;
220
+ disconnectedSessions . push ( sessionId ) ;
219
221
}
220
222
}
223
+
224
+ if ( disconnectedSessions . length === 0 ) { return ; } // Nothing to delete
225
+
226
+ // Delete all but the last one
227
+ for ( let i = 0 ; i < disconnectedSessions . length - 1 ; i ++ ) {
228
+ await this . delete ( disconnectedSessions [ i ] ) ;
229
+ }
230
+
231
+ // Handle the last one separately because there is no tab list trash icon to click on
232
+ const { state } = await this . getMetadata ( ) ;
233
+ if ( state === 'disconnected' || state === 'exited' ) {
234
+ await this . console . barTrashButton . click ( ) ;
235
+ }
221
236
} ) ;
222
237
}
223
238
@@ -385,11 +400,22 @@ export class Sessions {
385
400
* Note: Sessions that are disconnected are filtered out
386
401
*/
387
402
async getActiveSessions ( ) : Promise < QuickPickSessionInfo [ ] > {
388
- const allSessions = await this . sessionTabs . all ( ) ;
403
+ const allSessionTabs = await this . sessionTabs . all ( ) ;
404
+ const metadataButtonExists = await this . metadataButton . isVisible ( ) ;
405
+
406
+ if ( allSessionTabs . length === 0 ) {
407
+ // No active sessions
408
+ if ( ! metadataButtonExists ) { return [ ] ; }
409
+
410
+ // One session exists but the tab list is hidden
411
+ const { path, name, state } = await this . getMetadata ( ) ;
412
+ return state === 'disconnected' || state === 'exited' ? [ ] : [ { path, name } ] ;
413
+ }
389
414
415
+ // Multiple sessions are present
390
416
const activeSessions = (
391
417
await Promise . all (
392
- allSessions . map ( async session => {
418
+ allSessionTabs . map ( async session => {
393
419
const isDisconnected = await session . locator ( '.codicon-positron-status-disconnected' ) . isVisible ( ) ;
394
420
if ( isDisconnected ) { return null ; }
395
421
@@ -515,9 +541,17 @@ export class Sessions {
515
541
const activeSessionsFromConsole = await this . getActiveSessions ( ) ;
516
542
expect ( activeSessionsFromConsole ) . toHaveLength ( count ) ;
517
543
} else {
518
- await expect ( this . sessionTabs ) . toHaveCount ( count ) ;
544
+ if ( count === 0 ) {
545
+ await expect ( this . sessionTabs ) . not . toBeVisible ( ) ;
546
+ await expect ( this . metadataButton ) . not . toBeVisible ( ) ;
547
+ } else if ( count === 1 ) {
548
+ await expect ( this . sessionTabs ) . not . toBeVisible ( ) ;
549
+ await expect ( this . metadataButton ) . toBeVisible ( ) ;
550
+ } else {
551
+ await expect ( this . sessionTabs ) . toHaveCount ( count ) ;
552
+ }
519
553
}
520
- } ) . toPass ( { timeout : 5000 } ) ;
554
+ } ) . toPass ( { timeout : 45000 } ) ;
521
555
} ) ;
522
556
}
523
557
0 commit comments