@@ -112,12 +112,20 @@ describe('JestExt', () => {
112
112
const coverageCodeLensProvider : any = override ?. coverageCodeLensProvider ?? {
113
113
coverageChanged : jest . fn ( ) ,
114
114
} ;
115
- return new JestExt (
115
+
116
+ // Make a JestExt instance
117
+ const jestExtInstance = new JestExt (
116
118
context ,
117
119
workspaceFolder ,
118
120
debugConfigurationProvider ,
119
121
coverageCodeLensProvider
120
122
) ;
123
+
124
+ // Mock the new methods on testResultProvider
125
+ jestExtInstance . testResultProvider . markTestFileListDirty = jest . fn ( ) ;
126
+ jestExtInstance . testResultProvider . isTestFileListDirty = jest . fn ( ) . mockReturnValue ( false ) ;
127
+
128
+ return jestExtInstance ;
121
129
} ;
122
130
const mockEditor = ( fileName : string , languageId = 'typescript' ) : any => {
123
131
return {
@@ -178,6 +186,22 @@ describe('JestExt', () => {
178
186
let startDebugging ;
179
187
const mockShowQuickPick = jest . fn ( ) ;
180
188
let mockConfigurations = [ ] ;
189
+
190
+ it ( 'should update test file list if marked as dirty before debugging' , async ( ) => {
191
+ const sut = newJestExt ( ) ;
192
+ // Mock that test file list is dirty
193
+ ( sut . testResultProvider . isTestFileListDirty as jest . Mock ) . mockReturnValueOnce ( true ) ;
194
+
195
+ // Set up updateTestFileList to resolve immediately when called
196
+ const updateTestFileListSpy = jest . spyOn ( sut as any , 'updateTestFileList' ) . mockResolvedValueOnce ( undefined ) ;
197
+
198
+ await sut . debugTests ( { testPath : document . fileName , testName : 'testName' } ) ;
199
+
200
+ // Verify updateTestFileList was called before debugging
201
+ expect ( updateTestFileListSpy ) . toHaveBeenCalled ( ) ;
202
+ expect ( sut . debugConfigurationProvider . prepareTestRun ) . toHaveBeenCalled ( ) ;
203
+ } ) ;
204
+
181
205
beforeEach ( ( ) => {
182
206
startDebugging = vscode . debug . startDebugging as unknown as jest . Mock < { } > ;
183
207
( startDebugging as unknown as jest . Mock < { } > ) . mockImplementation (
@@ -752,6 +776,19 @@ describe('JestExt', () => {
752
776
expect ( mockTestProvider . dispose ) . toHaveBeenCalledTimes ( 1 ) ;
753
777
expect ( JestTestProvider ) . toHaveBeenCalledTimes ( 2 ) ;
754
778
} ) ;
779
+
780
+ it ( 'forces update of test file list on session start' , async ( ) => {
781
+ const sut = createJestExt ( ) ;
782
+
783
+ // Set up spy to check how updateTestFileList is called
784
+ const updateTestFileListSpy = jest . spyOn ( sut as any , 'updateTestFileList' ) ;
785
+
786
+ await sut . startSession ( ) ;
787
+
788
+ // Verify updateTestFileList was called with force=true
789
+ expect ( updateTestFileListSpy ) . toHaveBeenCalledWith ( true ) ;
790
+ } ) ;
791
+
755
792
describe ( 'will update test file list' , ( ) => {
756
793
it . each `
757
794
fileNames | error | expectedTestFiles
@@ -861,6 +898,21 @@ describe('JestExt', () => {
861
898
} ) ;
862
899
} ) ;
863
900
describe ( 'runAllTests' , ( ) => {
901
+ it ( 'should update test file list if marked as dirty before running tests' , async ( ) => {
902
+ const sut = newJestExt ( ) ;
903
+ // Mock that test file list is dirty
904
+ ( sut . testResultProvider . isTestFileListDirty as jest . Mock ) . mockReturnValueOnce ( true ) ;
905
+
906
+ // Set up updateTestFileList to resolve immediately when called
907
+ const updateTestFileListSpy = jest . spyOn ( sut as any , 'updateTestFileList' ) . mockResolvedValueOnce ( undefined ) ;
908
+
909
+ await sut . runAllTests ( ) ;
910
+
911
+ // Verify updateTestFileList was called before scheduling process
912
+ expect ( updateTestFileListSpy ) . toHaveBeenCalled ( ) ;
913
+ expect ( mockProcessSession . scheduleProcess ) . toHaveBeenCalled ( ) ;
914
+ } ) ;
915
+
864
916
describe . each `
865
917
scheduleProcess
866
918
${ { } }
@@ -934,29 +986,25 @@ describe('JestExt', () => {
934
986
}
935
987
) ;
936
988
} ) ;
937
- describe ( 'refresh test file list upon file system change' , ( ) => {
938
- const getProcessType = ( ) => {
939
- const { type } = mockProcessSession . scheduleProcess . mock . calls [ 0 ] [ 0 ] ;
940
- return type ;
941
- } ;
989
+ describe ( 'mark test file list as dirty upon file system change' , ( ) => {
942
990
let jestExt : any ;
943
991
beforeEach ( ( ) => {
944
992
jestExt = newJestExt ( ) ;
945
993
} ) ;
946
994
it ( 'when new file is created' , ( ) => {
947
995
jestExt . onDidCreateFiles ( { } ) ;
948
- expect ( mockProcessSession . scheduleProcess ) . toHaveBeenCalledTimes ( 1 ) ;
949
- expect ( getProcessType ( ) ) . toEqual ( 'list-test-files' ) ;
996
+ expect ( jestExt . testResultProvider . markTestFileListDirty ) . toHaveBeenCalled ( ) ;
997
+ expect ( mockProcessSession . scheduleProcess ) . not . toHaveBeenCalled ( ) ;
950
998
} ) ;
951
999
it ( 'when file is renamed' , ( ) => {
952
1000
jestExt . onDidRenameFiles ( { } ) ;
953
- expect ( mockProcessSession . scheduleProcess ) . toHaveBeenCalledTimes ( 1 ) ;
954
- expect ( getProcessType ( ) ) . toEqual ( 'list-test-files' ) ;
1001
+ expect ( jestExt . testResultProvider . markTestFileListDirty ) . toHaveBeenCalled ( ) ;
1002
+ expect ( mockProcessSession . scheduleProcess ) . not . toHaveBeenCalled ( ) ;
955
1003
} ) ;
956
1004
it ( 'when file is deleted' , ( ) => {
957
1005
jestExt . onDidDeleteFiles ( { } ) ;
958
- expect ( mockProcessSession . scheduleProcess ) . toHaveBeenCalledTimes ( 1 ) ;
959
- expect ( getProcessType ( ) ) . toEqual ( 'list-test-files' ) ;
1006
+ expect ( jestExt . testResultProvider . markTestFileListDirty ) . toHaveBeenCalled ( ) ;
1007
+ expect ( mockProcessSession . scheduleProcess ) . not . toHaveBeenCalled ( ) ;
960
1008
} ) ;
961
1009
} ) ;
962
1010
describe ( 'triggerUpdateSettings' , ( ) => {
0 commit comments