@@ -34,10 +34,11 @@ import { FileType } from '../vscode-api/workspace-fs-provider';
3434
3535const WORKSPACE_PATH = __dirname ;
3636
37- const SOLUTION_URI_DEFAULT = URI . file ( path . join ( WORKSPACE_PATH , 'test.csolution.yml' ) ) ;
38- const SOLUTION_URI_FOO = URI . file ( path . join ( WORKSPACE_PATH , 'foo' , 'Foo.csolution.yml' ) ) ;
39- const SOLUTION_URI_BAR = URI . file ( path . join ( WORKSPACE_PATH , 'bar' , 'Bar.csolution.yml' ) ) ;
40- const SOLUTION_URI_NEW = URI . file ( path . join ( WORKSPACE_PATH , 'new' , 'New.csolution.yml' ) ) ;
37+ const SOLUTION_URI_DEFAULT = URI . file ( path . join ( WORKSPACE_PATH , 'test.csolution.yml' ) ) ;
38+ const SOLUTION_URI_FOO = URI . file ( path . join ( WORKSPACE_PATH , 'foo' , 'Foo.csolution.yml' ) ) ;
39+ const SOLUTION_URI_BAR = URI . file ( path . join ( WORKSPACE_PATH , 'bar' , 'Bar.csolution.yml' ) ) ;
40+ const SOLUTION_URI_BAZ = URI . file ( path . join ( WORKSPACE_PATH , 'baz' , 'Baz.csolution.yml' ) ) ;
41+ const SOLUTION_URI_NEW = URI . file ( path . join ( WORKSPACE_PATH , 'new' , 'New.csolution.yml' ) ) ;
4142
4243describe ( 'ActiveSolutionTracker' , ( ) => {
4344 let changeSolutionsListener : jest . Mock ;
@@ -63,12 +64,6 @@ describe('ActiveSolutionTracker', () => {
6364 } ,
6465 } ;
6566
66- ( vscode . workspace . findFiles as jest . Mock ) . mockResolvedValue ( [
67- SOLUTION_URI_FOO ,
68- SOLUTION_URI_BAR ,
69- SOLUTION_URI_DEFAULT ,
70- ] ) ;
71-
7267 changeSolutionsListener = jest . fn ( ) ;
7368 changeActiveListener = jest . fn ( ) ;
7469
@@ -78,6 +73,12 @@ describe('ActiveSolutionTracker', () => {
7873 configurationProvider = configurationProviderFactory ( ) ;
7974 workspaceFsProvider = workspaceFsProviderFactory ( ) ;
8075
76+ workspaceFoldersProvider . findFiles . mockResolvedValue ( [
77+ SOLUTION_URI_FOO ,
78+ SOLUTION_URI_BAR ,
79+ SOLUTION_URI_DEFAULT ,
80+ ] ) ;
81+
8182 activeSolutionTracker = new ActiveSolutionTrackerImpl (
8283 messageProviderFactory ( ) ,
8384 commandsProvider ,
@@ -99,65 +100,50 @@ describe('ActiveSolutionTracker', () => {
99100 } ) ;
100101
101102 it ( 'searches for solution files on activation' , async ( ) => {
102- await activeSolutionTracker . activate ( context as unknown as vscode . ExtensionContext ) ;
103- await waitForCondition (
104- async ( ) => ( vscode . workspace . findFiles as jest . Mock ) . mock . calls . length > 0 ,
105- 'solution file search to be triggered after activation' ,
106- 200 ,
107- ) ;
108-
109- expect ( vscode . workspace . findFiles ) . toHaveBeenCalledTimes ( 1 ) ;
110- expect ( vscode . workspace . findFiles ) . toHaveBeenCalledWith ( ActiveSolutionTrackerImpl . GLOB_PATTERN , undefined ) ;
103+ activeSolutionTracker . activate ( context as unknown as vscode . ExtensionContext ) ;
104+ await waitForEvent ( activeSolutionTracker . onDidChangeSolutions , undefined , 200 ) ; ;
105+ expect ( workspaceFoldersProvider . findFiles ) . toHaveBeenCalledTimes ( 1 ) ;
106+ expect ( workspaceFoldersProvider . findFiles ) . toHaveBeenCalledWith ( ActiveSolutionTrackerImpl . GLOB_PATTERN , undefined ) ;
111107 } ) ;
112108
113109 it ( 'uses the configured glob pattern for searches' , async ( ) => {
114110 const testGlobPattern = `**/${ faker . system . commonFileName ( ) } ` ;
115111 configurationProvider . getConfigVariable . mockImplementation ( ( name : string ) => name === manifest . CONFIG_EXCLUDE ? testGlobPattern : undefined ) ;
116112
117- await activeSolutionTracker . activate ( context as unknown as vscode . ExtensionContext ) ;
118- await waitForCondition (
119- async ( ) => ( vscode . workspace . findFiles as jest . Mock ) . mock . calls . length > 0 ,
120- 'solution file search to be triggered with configured exclude glob' ,
121- 200 ,
122- ) ;
113+ activeSolutionTracker . activate ( context as unknown as vscode . ExtensionContext ) ;
114+ await waitForEvent ( activeSolutionTracker . onDidChangeSolutions , undefined , 200 ) ; ;
123115
124- expect ( vscode . workspace . findFiles ) . toHaveBeenCalledTimes ( 1 ) ;
125- expect ( vscode . workspace . findFiles ) . toHaveBeenCalledWith ( ActiveSolutionTrackerImpl . GLOB_PATTERN , testGlobPattern ) ;
116+ expect ( workspaceFoldersProvider . findFiles ) . toHaveBeenCalledTimes ( 1 ) ;
117+ expect ( workspaceFoldersProvider . findFiles ) . toHaveBeenCalledWith ( ActiveSolutionTrackerImpl . GLOB_PATTERN , testGlobPattern ) ;
126118 } ) ;
127119
128120 it ( 'updates when the configured glob pattern changes' , async ( ) => {
129- await activeSolutionTracker . activate ( context as unknown as vscode . ExtensionContext ) ;
130- await waitForCondition (
131- async ( ) => ( vscode . workspace . findFiles as jest . Mock ) . mock . calls . length > 0 ,
132- 'initial solution file search to complete' ,
133- 200 ,
134- ) ;
135-
136- ( vscode . workspace . findFiles as jest . Mock ) . mockClear ( ) ;
121+ activeSolutionTracker . activate ( context as unknown as vscode . ExtensionContext ) ;
122+ await waitForEvent ( activeSolutionTracker . onDidChangeSolutions , undefined , 200 ) ; ;
137123
138124 expect ( configurationProvider . onChangeConfiguration ) . toHaveBeenCalledTimes ( 1 ) ;
139125 expect ( configurationProvider . onChangeConfiguration ) . toHaveBeenCalledWith ( expect . any ( Function ) , manifest . CONFIG_EXCLUDE ) ;
140126
127+ workspaceFoldersProvider . findFiles . mockClear ( ) ;
128+
141129 const testGlobPattern = `**/${ faker . system . commonFileName ( ) } ` ;
142130 configurationProvider . getConfigVariable . mockImplementation ( ( name : string ) => name === manifest . CONFIG_EXCLUDE ? testGlobPattern : undefined ) ;
143131 configurationProvider . onChangeConfiguration . mock . calls [ 0 ] [ 0 ] ( ) ;
144- await waitForCondition (
145- async ( ) => ( vscode . workspace . findFiles as jest . Mock ) . mock . calls . length > 0 ,
146- 'solution file search to run after configuration change' ,
147- 200 ,
148- ) ;
149132
150- expect ( vscode . workspace . findFiles ) . toHaveBeenCalledTimes ( 1 ) ;
151- expect ( vscode . workspace . findFiles ) . toHaveBeenCalledWith ( ActiveSolutionTrackerImpl . GLOB_PATTERN , testGlobPattern ) ;
133+ workspaceFoldersProvider . findFiles . mockResolvedValue ( [ SOLUTION_URI_BAZ ] ) ;
134+ await waitForEvent ( activeSolutionTracker . onDidChangeSolutions , undefined , 200 ) ; ;
135+
136+ expect ( workspaceFoldersProvider . findFiles ) . toHaveBeenCalledTimes ( 1 ) ;
137+ expect ( workspaceFoldersProvider . findFiles ) . toHaveBeenCalledWith ( ActiveSolutionTrackerImpl . GLOB_PATTERN , testGlobPattern ) ;
152138 } ) ;
153139
154140 describe ( 'activated with no solutions in the workspace' , ( ) => {
155141 beforeEach ( async ( ) => {
156- ( vscode . workspace . findFiles as jest . Mock ) . mockResolvedValue ( [ ] ) ;
142+ workspaceFoldersProvider . findFiles . mockResolvedValue ( [ ] ) ;
157143
158- await activeSolutionTracker . activate ( context as unknown as vscode . ExtensionContext ) ;
144+ activeSolutionTracker . activate ( context as unknown as vscode . ExtensionContext ) ;
159145 await waitForCondition (
160- async ( ) => ( vscode . workspace . findFiles as jest . Mock ) . mock . calls . length > 0 ,
146+ async ( ) => workspaceFoldersProvider . findFiles . mock . calls . length > 0 ,
161147 'solution file search to complete in empty workspace' ,
162148 200 ,
163149 ) ;
@@ -177,7 +163,7 @@ describe('ActiveSolutionTracker', () => {
177163
178164 describe ( 'activated with solutions in the workspace and no previous selection' , ( ) => {
179165 beforeEach ( async ( ) => {
180- await activeSolutionTracker . activate ( context as unknown as vscode . ExtensionContext ) ;
166+ activeSolutionTracker . activate ( context as unknown as vscode . ExtensionContext ) ;
181167 await waitForEvent ( activeSolutionTracker . onDidChangeActiveSolution ) ;
182168 } ) ;
183169
@@ -204,8 +190,8 @@ describe('ActiveSolutionTracker', () => {
204190 key => key === ActiveSolutionTrackerImpl . ACTIVE_SOLUTION_KEY ? SOLUTION_URI_FOO . fsPath : undefined
205191 ) ;
206192
207- await activeSolutionTracker . activate ( context as unknown as vscode . ExtensionContext ) ;
208- await waitForEvent ( activeSolutionTracker . onDidChangeActiveSolution ) ;
193+ activeSolutionTracker . activate ( context as unknown as vscode . ExtensionContext ) ;
194+ await waitForEvent ( activeSolutionTracker . onDidChangeActiveSolution , undefined , 200 ) ;
209195 } ) ;
210196
211197 it ( 'preserves the previous selection' , ( ) => {
@@ -221,8 +207,8 @@ describe('ActiveSolutionTracker', () => {
221207 key => key === ActiveSolutionTrackerImpl . ACTIVE_SOLUTION_KEY ? URI . file ( path . join ( WORKSPACE_PATH , 'baz' , 'Baz.csolution.yml' ) ) . fsPath : undefined
222208 ) ;
223209
224- await activeSolutionTracker . activate ( context as unknown as vscode . ExtensionContext ) ;
225- await waitForEvent ( activeSolutionTracker . onDidChangeActiveSolution ) ;
210+ activeSolutionTracker . activate ( context as unknown as vscode . ExtensionContext ) ;
211+ await waitForEvent ( activeSolutionTracker . onDidChangeActiveSolution , undefined , 200 ) ;
226212 } ) ;
227213
228214 it ( 'selects the first solution as active' , ( ) => {
@@ -240,15 +226,15 @@ describe('ActiveSolutionTracker', () => {
240226
241227 describe ( 'activated with solutions in workspace subfolders only' , ( ) => {
242228 beforeEach ( async ( ) => {
243- ( vscode . workspace . findFiles as jest . Mock ) . mockResolvedValue ( [
229+ workspaceFoldersProvider . findFiles . mockResolvedValue ( [
244230 SOLUTION_URI_FOO ,
245231 SOLUTION_URI_BAR ,
246232 ] ) ;
247233 } ) ;
248234
249235 it ( 'selects no active solution' , async ( ) => {
250- await activeSolutionTracker . activate ( context as unknown as vscode . ExtensionContext ) ;
251- await waitForEvent ( activeSolutionTracker . onDidChangeSolutions ) ;
236+ activeSolutionTracker . activate ( context as unknown as vscode . ExtensionContext ) ;
237+ await waitForEvent ( activeSolutionTracker . onDidChangeSolutions , undefined , 200 ) ;
252238
253239 expect ( activeSolutionTracker . solutions ) . toEqual ( [
254240 SOLUTION_URI_BAR . fsPath ,
@@ -268,8 +254,8 @@ describe('ActiveSolutionTracker', () => {
268254
269255 describe ( 'after activation' , ( ) => {
270256 beforeEach ( async ( ) => {
271- await activeSolutionTracker . activate ( context as unknown as vscode . ExtensionContext ) ;
272- await waitForEvent ( activeSolutionTracker . onDidChangeActiveSolution ) ;
257+ activeSolutionTracker . activate ( context as unknown as vscode . ExtensionContext ) ;
258+ await waitForEvent ( activeSolutionTracker . onDidChangeActiveSolution , undefined , 200 ) ;
273259 changeActiveListener . mockClear ( ) ;
274260 changeSolutionsListener . mockClear ( ) ;
275261 } ) ;
@@ -282,9 +268,11 @@ describe('ActiveSolutionTracker', () => {
282268 expect ( changeActiveListener ) . not . toHaveBeenCalled ( ) ;
283269 } ) ;
284270
285- it ( 'sets a new solution as active' , ( ) => {
271+ it ( 'sets a new solution as active' , async ( ) => {
286272 const solutionPath = SOLUTION_URI_FOO . fsPath ;
273+ const activeSolutionChanged = waitForEvent ( activeSolutionTracker . onDidChangeActiveSolution ) ;
287274 activeSolutionTracker . activeSolution = solutionPath ;
275+ await activeSolutionChanged ;
288276
289277 expect ( activeSolutionTracker . activeSolution ) . toBe ( solutionPath ) ;
290278 expect ( changeActiveListener ) . toHaveBeenCalled ( ) ;
@@ -301,15 +289,15 @@ describe('ActiveSolutionTracker', () => {
301289 } ) ;
302290
303291 it ( 'updates the list of solutions when a new solution file is added' , async ( ) => {
304- ( vscode . workspace . findFiles as jest . Mock ) . mockResolvedValue ( [
292+ workspaceFoldersProvider . findFiles . mockResolvedValue ( [
305293 SOLUTION_URI_NEW ,
306294 SOLUTION_URI_FOO ,
307295 SOLUTION_URI_BAR
308296 ] ) ;
309297
310298 fileWatcherProvider . mockFireEvent ( ActiveSolutionTrackerImpl . GLOB_PATTERN , '/' , 'create' ) ;
311299
312- await waitForEvent ( activeSolutionTracker . onDidChangeSolutions ) ;
300+ await waitForEvent ( activeSolutionTracker . onDidChangeSolutions , undefined , 200 ) ;
313301
314302 expect ( activeSolutionTracker . solutions ) . toEqual ( [
315303 SOLUTION_URI_BAR . fsPath ,
@@ -321,13 +309,13 @@ describe('ActiveSolutionTracker', () => {
321309 } ) ;
322310
323311 it ( 'updates the list of solutions when a solution file is deleted' , async ( ) => {
324- ( vscode . workspace . findFiles as jest . Mock ) . mockResolvedValue ( [
312+ workspaceFoldersProvider . findFiles . mockResolvedValue ( [
325313 SOLUTION_URI_FOO ,
326314 ] ) ;
327315
328316 fileWatcherProvider . mockFireEvent ( '**/*' , SOLUTION_URI_BAR . fsPath , 'delete' ) ;
329317
330- await waitForEvent ( activeSolutionTracker . onDidChangeSolutions ) ;
318+ await waitForEvent ( activeSolutionTracker . onDidChangeSolutions , undefined , 200 ) ;
331319
332320 expect ( activeSolutionTracker . solutions ) . toEqual ( [
333321 SOLUTION_URI_FOO . fsPath ,
@@ -337,13 +325,13 @@ describe('ActiveSolutionTracker', () => {
337325 } ) ;
338326
339327 it ( 'updates the list of solutions when a folder containing a solution file is deleted' , async ( ) => {
340- ( vscode . workspace . findFiles as jest . Mock ) . mockResolvedValue ( [
328+ workspaceFoldersProvider . findFiles . mockResolvedValue ( [
341329 SOLUTION_URI_FOO ,
342330 ] ) ;
343331
344332 fileWatcherProvider . mockFireEvent ( '**/*' , path . resolve ( SOLUTION_URI_BAR . fsPath , '..' ) , 'delete' ) ;
345333
346- await waitForEvent ( activeSolutionTracker . onDidChangeSolutions ) ;
334+ await waitForEvent ( activeSolutionTracker . onDidChangeSolutions , undefined , 200 ) ;
347335
348336 expect ( activeSolutionTracker . solutions ) . toEqual ( [
349337 SOLUTION_URI_FOO . fsPath ,
@@ -353,7 +341,7 @@ describe('ActiveSolutionTracker', () => {
353341 } ) ;
354342
355343 it ( 'updates the list of solutions when a new workspace folder is added' , async ( ) => {
356- ( vscode . workspace . findFiles as jest . Mock ) . mockResolvedValue ( [
344+ workspaceFoldersProvider . findFiles . mockResolvedValue ( [
357345 SOLUTION_URI_NEW ,
358346 SOLUTION_URI_FOO ,
359347 SOLUTION_URI_BAR
@@ -364,7 +352,7 @@ describe('ActiveSolutionTracker', () => {
364352 { uri : URI . file ( __dirname ) , name : 'Workspace Folder 2' , index : 2 }
365353 ] ) ;
366354
367- await waitForEvent ( activeSolutionTracker . onDidChangeSolutions ) ;
355+ await waitForEvent ( activeSolutionTracker . onDidChangeSolutions , undefined , 200 ) ;
368356
369357 expect ( activeSolutionTracker . solutions ) . toEqual ( [
370358 SOLUTION_URI_BAR . fsPath ,
@@ -490,14 +478,14 @@ describe('ActiveSolutionTracker solution file watching', () => {
490478 } ,
491479 } ;
492480
493- ( vscode . workspace . findFiles as jest . Mock ) . mockResolvedValue ( [ URI . file ( activeSolution ) ] ) ;
494-
495481 fileWatcherProvider = fileWatcherProviderFactory ( ) ;
496482 commandsProvider = commandsProviderFactory ( ) ;
497483 workspaceFoldersProvider = workspaceFoldersProviderFactory ( [ { uri : URI . file ( solutionRoot ) , name : 'workspace' , index : 0 } ] ) ;
498484 workspaceFsProvider = workspaceFsProviderFactory ( ) ;
499485 configurationProvider = configurationProviderFactory ( ) ;
500486
487+ workspaceFoldersProvider . findFiles . mockResolvedValue ( [ URI . file ( activeSolution ) ] ) ;
488+
501489 tracker = new ActiveSolutionTrackerImpl (
502490 messageProviderFactory ( ) ,
503491 commandsProvider ,
0 commit comments