@@ -8,35 +8,38 @@ import { MockFilesystem } from './mockFilesystem.js';
8
8
import { URI } from '../../../../../../../base/common/uri.js' ;
9
9
import { Schemas } from '../../../../../../../base/common/network.js' ;
10
10
import { assertDefined } from '../../../../../../../base/common/types.js' ;
11
- import { IFileService } from '../../../../../../../platform/files/common/files.js' ;
12
11
import { FileService } from '../../../../../../../platform/files/common/fileService.js' ;
13
12
import { ILogService , NullLogService } from '../../../../../../../platform/log/common/log.js' ;
13
+ import { IFileService , IFileStat } from '../../../../../../../platform/files/common/files.js' ;
14
14
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../../../base/test/common/utils.js' ;
15
15
import { InMemoryFileSystemProvider } from '../../../../../../../platform/files/common/inMemoryFilesystemProvider.js' ;
16
16
import { TestInstantiationService } from '../../../../../../../platform/instantiation/test/common/instantiationServiceMock.js' ;
17
17
18
18
/**
19
- * TODO: @legomushroom
19
+ * Base attribute for an expected filesystem node (a file or a folder).
20
20
*/
21
- interface IBase {
22
- resource : URI ;
23
- name : string ;
24
- isFile : boolean ;
25
- isDirectory : boolean ;
26
- isSymbolicLink : boolean ;
27
- }
21
+ interface IExpectedFilesystemNode extends Pick <
22
+ IFileStat ,
23
+ 'resource' | 'name' | 'isFile' | 'isDirectory' | 'isSymbolicLink'
24
+ > { }
28
25
29
26
/**
30
- * TODO: @legomushroom
27
+ * Represents an expected `file` info.
31
28
*/
32
- interface IExpectedFile extends IBase {
29
+ interface IExpectedFile extends IExpectedFilesystemNode {
30
+ /**
31
+ * Expected file contents.
32
+ */
33
33
contents : string ;
34
34
}
35
35
36
36
/**
37
- * TODO: @legomushroom
37
+ * Represents an expected `folder` info.
38
38
*/
39
- interface IExpectedFolder extends IBase {
39
+ interface IExpectedFolder extends IExpectedFilesystemNode {
40
+ /**
41
+ * Expected folder children.
42
+ */
40
43
children : ( IExpectedFolder | IExpectedFile ) [ ] ;
41
44
}
42
45
@@ -48,7 +51,12 @@ const validateFile = async (
48
51
expectedFile : IExpectedFile ,
49
52
fileService : IFileService ,
50
53
) => {
51
- const readFile = await fileService . resolve ( URI . file ( filePath ) ) ;
54
+ let readFile : IFileStat | undefined ;
55
+ try {
56
+ readFile = await fileService . resolve ( URI . file ( filePath ) ) ;
57
+ } catch ( error ) {
58
+ throw new Error ( `Failed to read file '${ filePath } ': ${ error } .` ) ;
59
+ }
52
60
53
61
assert . strictEqual (
54
62
readFile . name ,
@@ -59,34 +67,33 @@ const validateFile = async (
59
67
assert . deepStrictEqual (
60
68
readFile . resource ,
61
69
expectedFile . resource ,
62
- ' File must have correct ` URI`.' ,
70
+ ` File ' ${ filePath } ' must have correct ' URI'.` ,
63
71
) ;
64
72
65
73
assert . strictEqual (
66
74
readFile . isFile ,
67
75
expectedFile . isFile ,
68
- ' File must have correct ` isFile` value.' ,
76
+ ` File ' ${ filePath } ' must have correct ' isFile' value.` ,
69
77
) ;
70
78
71
79
assert . strictEqual (
72
80
readFile . isDirectory ,
73
81
expectedFile . isDirectory ,
74
- ' File must have correct ` isDirectory` value.' ,
82
+ ` File ' ${ filePath } ' must have correct ' isDirectory' value.` ,
75
83
) ;
76
84
77
85
assert . strictEqual (
78
86
readFile . isSymbolicLink ,
79
87
expectedFile . isSymbolicLink ,
80
- ' File must have correct ` isSymbolicLink` value.' ,
88
+ ` File ' ${ filePath } ' must have correct ' isSymbolicLink' value.` ,
81
89
) ;
82
90
83
91
assert . strictEqual (
84
92
readFile . children ,
85
93
undefined ,
86
- ' File must not have children.' ,
94
+ ` File ' ${ filePath } ' must not have children.` ,
87
95
) ;
88
96
89
- // TODO: @legomushroom - add folder/file path to all asserts
90
97
const fileContents = await fileService . readFile ( readFile . resource ) ;
91
98
assert . strictEqual (
92
99
fileContents . value . toString ( ) ,
@@ -103,49 +110,73 @@ const validateFolder = async (
103
110
expectedFolder : IExpectedFolder ,
104
111
fileService : IFileService ,
105
112
) => {
106
- const readFolder = await fileService . resolve ( URI . file ( folderPath ) ) ;
113
+ let readFolder : IFileStat | undefined ;
114
+ try {
115
+ readFolder = await fileService . resolve ( URI . file ( folderPath ) ) ;
116
+ } catch ( error ) {
117
+ throw new Error ( `Failed to read folder '${ folderPath } ': ${ error } .` ) ;
118
+ }
107
119
108
120
assert . strictEqual (
109
121
readFolder . name ,
110
122
expectedFolder . name ,
111
- ' Folder must have correct ` name`.' ,
123
+ ` Folder ' ${ folderPath } ' must have correct ' name'.` ,
112
124
) ;
113
125
114
126
assert . deepStrictEqual (
115
127
readFolder . resource ,
116
128
expectedFolder . resource ,
117
- ' Folder must have correct ` URI`.' ,
129
+ ` Folder ' ${ folderPath } ' must have correct ' URI'.` ,
118
130
) ;
119
131
120
132
assert . strictEqual (
121
133
readFolder . isFile ,
122
134
expectedFolder . isFile ,
123
- ' Folder must have correct ` isFile` value.' ,
135
+ ` Folder ' ${ folderPath } ' must have correct ' isFile' value.` ,
124
136
) ;
125
137
126
138
assert . strictEqual (
127
139
readFolder . isDirectory ,
128
140
expectedFolder . isDirectory ,
129
- ' Folder must have correct ` isDirectory` value.' ,
141
+ ` Folder ' ${ folderPath } ' must have correct ' isDirectory' value.` ,
130
142
) ;
131
143
132
144
assert . strictEqual (
133
145
readFolder . isSymbolicLink ,
134
146
expectedFolder . isSymbolicLink ,
135
- ' Folder must have correct ` isSymbolicLink` value.' ,
147
+ ` Folder ' ${ folderPath } ' must have correct ' isSymbolicLink' value.` ,
136
148
) ;
137
149
138
-
139
150
assertDefined (
140
151
readFolder . children ,
141
- ' Folder must have children.' ,
152
+ ` Folder ' ${ folderPath } ' must have children.` ,
142
153
) ;
143
154
144
155
assert . strictEqual (
145
156
readFolder . children . length ,
146
157
expectedFolder . children . length ,
147
- ' Folder must have correct number of children.' ,
158
+ ` Folder ' ${ folderPath } ' must have correct number of children.` ,
148
159
) ;
160
+
161
+ for ( const expectedChild of expectedFolder . children ) {
162
+ const childPath = URI . joinPath ( expectedFolder . resource , expectedChild . name ) . fsPath ;
163
+
164
+ if ( 'children' in expectedChild ) {
165
+ await validateFolder (
166
+ childPath ,
167
+ expectedChild ,
168
+ fileService ,
169
+ ) ;
170
+
171
+ continue ;
172
+ }
173
+
174
+ await validateFile (
175
+ childPath ,
176
+ expectedChild ,
177
+ fileService ,
178
+ ) ;
179
+ }
149
180
} ;
150
181
151
182
suite ( 'MockFilesystem' , ( ) => {
@@ -164,7 +195,7 @@ suite('MockFilesystem', () => {
164
195
initService . stub ( IFileService , fileService ) ;
165
196
} ) ;
166
197
167
- test ( 'mocks file structure' , async ( ) => {
198
+ test ( '• mocks file structure' , async ( ) => {
168
199
const mockFilesystem = initService . createInstance ( MockFilesystem , [
169
200
{
170
201
name : '/root/folder' ,
@@ -209,147 +240,50 @@ suite('MockFilesystem', () => {
209
240
isDirectory : true ,
210
241
isSymbolicLink : false ,
211
242
children : [
212
- // TODO: @legomushroom - add real children
213
- { } as any ,
214
- { } as any ,
215
- ] ,
216
- } ,
217
- fileService ,
218
- ) ;
219
-
220
- const rootFolder = await fileService . resolve ( URI . file ( '/root/folder' ) ) ;
221
-
222
- assertDefined (
223
- rootFolder . children ,
224
- 'Root folder must have children.' ,
225
- ) ;
226
-
227
- const file = rootFolder . children [ 0 ] ;
228
-
229
- await validateFile (
230
- '/root/folder/file.txt' ,
231
- {
232
- resource : URI . file ( '/root/folder/file.txt' ) ,
233
- name : 'file.txt' ,
234
- isFile : true ,
235
- isDirectory : false ,
236
- isSymbolicLink : false ,
237
- contents : 'contents' ,
238
- } ,
239
- fileService ,
240
- ) ;
241
-
242
- await validateFile (
243
- file . resource . fsPath ,
244
- {
245
- resource : URI . file ( '/root/folder/file.txt' ) ,
246
- name : 'file.txt' ,
247
- isFile : true ,
248
- isDirectory : false ,
249
- isSymbolicLink : false ,
250
- contents : 'contents' ,
251
- } ,
252
- fileService ,
253
- ) ;
254
-
255
- const subfolder = await fileService . resolve ( URI . file ( '/root/folder/Subfolder' ) ) ;
256
-
257
- await validateFolder (
258
- '/root/folder/Subfolder' ,
259
- {
260
- resource : URI . file ( '/root/folder/Subfolder' ) ,
261
- name : 'Subfolder' ,
262
- isFile : false ,
263
- isDirectory : true ,
264
- isSymbolicLink : false ,
265
- children : [
266
- // TODO: @legomushroom - add real children
267
- { } as any ,
268
- { } as any ,
269
- { } as any ,
243
+ {
244
+ resource : URI . file ( '/root/folder/file.txt' ) ,
245
+ name : 'file.txt' ,
246
+ isFile : true ,
247
+ isDirectory : false ,
248
+ isSymbolicLink : false ,
249
+ contents : 'contents' ,
250
+ } ,
251
+ {
252
+ resource : URI . file ( '/root/folder/Subfolder' ) ,
253
+ name : 'Subfolder' ,
254
+ isFile : false ,
255
+ isDirectory : true ,
256
+ isSymbolicLink : false ,
257
+ children : [
258
+ {
259
+ resource : URI . file ( '/root/folder/Subfolder/test.ts' ) ,
260
+ name : 'test.ts' ,
261
+ isFile : true ,
262
+ isDirectory : false ,
263
+ isSymbolicLink : false ,
264
+ contents : 'other contents' ,
265
+ } ,
266
+ {
267
+ resource : URI . file ( '/root/folder/Subfolder/file.test.ts' ) ,
268
+ name : 'file.test.ts' ,
269
+ isFile : true ,
270
+ isDirectory : false ,
271
+ isSymbolicLink : false ,
272
+ contents : 'hello test' ,
273
+ } ,
274
+ {
275
+ resource : URI . file ( '/root/folder/Subfolder/.file-2.TEST.ts' ) ,
276
+ name : '.file-2.TEST.ts' ,
277
+ isFile : true ,
278
+ isDirectory : false ,
279
+ isSymbolicLink : false ,
280
+ contents : 'test hello' ,
281
+ } ,
282
+ ] ,
283
+ }
270
284
] ,
271
285
} ,
272
286
fileService ,
273
287
) ;
274
-
275
- assertDefined (
276
- subfolder . children ,
277
- 'Subfolder must have children.' ,
278
- ) ;
279
-
280
- await validateFile (
281
- '/root/folder/Subfolder/test.ts' ,
282
- {
283
- resource : URI . file ( '/root/folder/Subfolder/test.ts' ) ,
284
- name : 'test.ts' ,
285
- isFile : true ,
286
- isDirectory : false ,
287
- isSymbolicLink : false ,
288
- contents : 'other contents' ,
289
- } ,
290
- fileService ,
291
- ) ;
292
- await validateFile (
293
- subfolder . children [ 0 ] . resource . fsPath ,
294
- {
295
- resource : URI . file ( '/root/folder/Subfolder/test.ts' ) ,
296
- name : 'test.ts' ,
297
- isFile : true ,
298
- isDirectory : false ,
299
- isSymbolicLink : false ,
300
- contents : 'other contents' ,
301
- } ,
302
- fileService ,
303
- ) ;
304
-
305
- await validateFile (
306
- '/root/folder/Subfolder/file.test.ts' ,
307
- {
308
- resource : URI . file ( '/root/folder/Subfolder/file.test.ts' ) ,
309
- name : 'file.test.ts' ,
310
- isFile : true ,
311
- isDirectory : false ,
312
- isSymbolicLink : false ,
313
- contents : 'hello test' ,
314
- } ,
315
- fileService ,
316
- ) ;
317
- await validateFile (
318
- subfolder . children [ 1 ] . resource . fsPath ,
319
- {
320
- resource : URI . file ( '/root/folder/Subfolder/file.test.ts' ) ,
321
- name : 'file.test.ts' ,
322
- isFile : true ,
323
- isDirectory : false ,
324
- isSymbolicLink : false ,
325
- contents : 'hello test' ,
326
- } ,
327
- fileService ,
328
- ) ;
329
-
330
- await validateFile (
331
- '/root/folder/Subfolder/.file-2.TEST.ts' ,
332
- {
333
- resource : URI . file ( '/root/folder/Subfolder/.file-2.TEST.ts' ) ,
334
- name : '.file-2.TEST.ts' ,
335
- isFile : true ,
336
- isDirectory : false ,
337
- isSymbolicLink : false ,
338
- contents : 'test hello' ,
339
- } ,
340
- fileService ,
341
- ) ;
342
- await validateFile (
343
- subfolder . children [ 2 ] . resource . fsPath ,
344
- {
345
- resource : URI . file ( '/root/folder/Subfolder/.file-2.TEST.ts' ) ,
346
- name : '.file-2.TEST.ts' ,
347
- isFile : true ,
348
- isDirectory : false ,
349
- isSymbolicLink : false ,
350
- contents : 'test hello' ,
351
- } ,
352
- fileService ,
353
- ) ;
354
288
} ) ;
355
289
} ) ;
0 commit comments