@@ -280,9 +280,7 @@ export class JestExt {
280
280
this . testProvider = new JestTestProvider ( this . getExtExplorerContext ( ) ) ;
281
281
this . resetStatusBar ( ) ;
282
282
283
- vscode . window . visibleTextEditors . forEach ( ( editor ) => {
284
- this . triggerUpdateActiveEditor ( editor ) ;
285
- } ) ;
283
+ this . updateVisibleTextEditors ( ) ;
286
284
return ;
287
285
}
288
286
@@ -310,9 +308,7 @@ export class JestExt {
310
308
await this . updateTestFileList ( ) ;
311
309
312
310
// update visible editors that belong to this folder
313
- vscode . window . visibleTextEditors . forEach ( ( editor ) => {
314
- this . triggerUpdateActiveEditor ( editor ) ;
315
- } ) ;
311
+ this . updateVisibleTextEditors ( ) ;
316
312
} catch ( e ) {
317
313
this . outputActionMessages (
318
314
`Failed to start jest session: ${ e } ` ,
@@ -372,13 +368,8 @@ export class JestExt {
372
368
updateCurrentDiagnostics ( sortedResults . fail , this . failDiagnostics , editor ) ;
373
369
}
374
370
375
- public triggerUpdateActiveEditor ( editor : vscode . TextEditor ) : void {
376
- // there is use case that the active editor is not in the workspace but is in jest test file list
377
- if ( ! this . isInWorkspaceFolder ( editor ) && ! this . isTestFileEditor ( editor ) ) {
378
- return ;
379
- }
380
- this . coverageOverlay . updateVisibleEditors ( ) ;
381
-
371
+ private triggerUpdateActiveEditor ( editor : vscode . TextEditor ) : void {
372
+ this . coverageOverlay . update ( editor ) ;
382
373
this . updateTestFileEditor ( editor ) ;
383
374
}
384
375
@@ -420,6 +411,25 @@ export class JestExt {
420
411
await this . startSession ( true ) ;
421
412
}
422
413
414
+ /**
415
+ * Updates the valid text editors based on the specified document.
416
+ * If a document is provided, it triggers an update for the active editor matches the document.
417
+ * If no document is provided, it triggers an update for all editors that are in the workspace folder
418
+ *
419
+ * @param document The document to match against the active editor. Optional.
420
+ */
421
+ private updateVisibleTextEditors ( document ?: vscode . TextDocument ) : void {
422
+ vscode . window . visibleTextEditors . forEach ( ( editor ) => {
423
+ if ( document ) {
424
+ if ( editor . document === document ) {
425
+ this . triggerUpdateActiveEditor ( editor ) ;
426
+ }
427
+ } else if ( this . isInWorkspaceFolder ( editor ) ) {
428
+ this . triggerUpdateActiveEditor ( editor ) ;
429
+ }
430
+ } ) ;
431
+ }
432
+
423
433
private isInWorkspaceFolder ( editor : vscode . TextEditor ) : boolean {
424
434
return isInFolder ( editor . document . uri , this . extContext . workspace ) ;
425
435
}
@@ -434,12 +444,7 @@ export class JestExt {
434
444
return false ;
435
445
}
436
446
437
- if ( this . testResultProvider . isTestFile ( editor . document . fileName ) === 'no' ) {
438
- return false ;
439
- }
440
-
441
- // if isTestFile returns unknown or true, treated it like a test file to give it best chance to display any test result if ever available
442
- return true ;
447
+ return this . testResultProvider . isTestFile ( editor . document . fileName ) ;
443
448
}
444
449
445
450
/**
@@ -613,7 +618,7 @@ export class JestExt {
613
618
} else {
614
619
const name = editor . document . fileName ;
615
620
let pInfo ;
616
- if ( this . testResultProvider . isTestFile ( name ) !== 'yes' ) {
621
+ if ( ! this . testResultProvider . isTestFile ( name ) ) {
617
622
// run related tests from source file
618
623
pInfo = this . processSession . scheduleProcess ( {
619
624
type : 'by-file' ,
@@ -670,14 +675,14 @@ export class JestExt {
670
675
}
671
676
const isTestFile = this . testResultProvider . isTestFile ( document . fileName ) ;
672
677
673
- if ( isTestFile === 'no' && this . extContext . settings . runMode . config . testFileOnly ) {
678
+ if ( ! isTestFile && this . extContext . settings . runMode . config . testFileOnly ) {
674
679
// not a test file and configured not to re-run test for non-test files => mark the workspace dirty
675
680
this . dirtyFiles . add ( document . fileName ) ;
676
681
} else {
677
682
this . processSession . scheduleProcess ( {
678
683
type : 'by-file' ,
679
684
testFileName : document . fileName ,
680
- notTestFile : isTestFile !== 'yes' ,
685
+ notTestFile : ! isTestFile ,
681
686
} ) ;
682
687
}
683
688
}
@@ -687,15 +692,7 @@ export class JestExt {
687
692
* @param document refresh UI for the specific document. if undefined, refresh all active editors in the workspace.
688
693
*/
689
694
private refreshDocumentChange ( document ?: vscode . TextDocument ) : void {
690
- for ( const editor of vscode . window . visibleTextEditors ) {
691
- if (
692
- ( document && editor . document === document ) ||
693
- this . isInWorkspaceFolder ( editor ) ||
694
- this . isTestFileEditor ( editor )
695
- ) {
696
- this . triggerUpdateActiveEditor ( editor ) ;
697
- }
698
- }
695
+ this . updateVisibleTextEditors ( document ) ;
699
696
700
697
this . updateStatusBar ( {
701
698
stats : this . toSBStats ( this . testResultProvider . getTestSuiteStats ( ) ) ,
0 commit comments