@@ -10,6 +10,7 @@ import * as vscode from 'vscode'
10
10
import * as fs from 'fs'
11
11
import {
12
12
collectFiles ,
13
+ collectFilesForIndex ,
13
14
findParentProjectFile ,
14
15
getWorkspaceFoldersByPrefixes ,
15
16
getWorkspaceRelativePath ,
@@ -426,3 +427,75 @@ describe('getWorkspaceFoldersByPrefixes', function () {
426
427
)
427
428
} )
428
429
} )
430
+
431
+ describe ( 'collectFilesForIndex' , function ( ) {
432
+ it ( 'returns all files in the workspace not excluded by gitignore and is a supported programming language' , async function ( ) {
433
+ // these variables are a manual selection of settings for the test in order to test the collectFiles function
434
+ const fileAmount = 3
435
+ const fileNamePrefix = 'file'
436
+ const fileContent = 'test content'
437
+
438
+ const workspaceFolder = await createTestWorkspace ( fileAmount , { fileNamePrefix, fileContent } )
439
+
440
+ const writeFile = ( pathParts : string [ ] , fileContent : string ) => {
441
+ return toFile ( fileContent , workspaceFolder . uri . fsPath , ...pathParts )
442
+ }
443
+
444
+ sinon . stub ( vscode . workspace , 'workspaceFolders' ) . value ( [ workspaceFolder ] )
445
+ const gitignoreContent = `file2
446
+ # different formats of prefixes
447
+ /build
448
+ node_modules
449
+
450
+ #some comment
451
+
452
+ range_file[0-5]
453
+ `
454
+ await writeFile ( [ '.gitignore' ] , gitignoreContent )
455
+
456
+ await writeFile ( [ 'build' , `ignored1` ] , fileContent )
457
+ await writeFile ( [ 'build' , `ignored2` ] , fileContent )
458
+
459
+ await writeFile ( [ 'node_modules' , `ignored1` ] , fileContent )
460
+ await writeFile ( [ 'node_modules' , `ignored2` ] , fileContent )
461
+
462
+ await writeFile ( [ `range_file0` ] , fileContent )
463
+ await writeFile ( [ `range_file9` ] , fileContent )
464
+
465
+ const gitignore2 = 'folder1\n'
466
+ await writeFile ( [ 'src' , '.gitignore' ] , gitignore2 )
467
+ await writeFile ( [ 'src' , 'folder2' , 'a.js' ] , fileContent )
468
+ await writeFile ( [ 'src' , 'folder2' , 'b.cs' ] , fileContent )
469
+ await writeFile ( [ 'src' , 'folder2' , 'c.bin' ] , fileContent )
470
+ await writeFile ( [ 'src' , 'folder2' , 'd.pyc' ] , fileContent )
471
+
472
+ const gitignore3 = `negate_test*
473
+ !negate_test[0-5]`
474
+ await writeFile ( [ 'src' , 'folder3' , '.gitignore' ] , gitignore3 )
475
+ await writeFile ( [ 'src' , 'folder3' , 'negate_test1' ] , fileContent )
476
+ await writeFile ( [ 'src' , 'folder3' , 'negate_test6' ] , fileContent )
477
+
478
+ const result = ( await collectFilesForIndex ( [ workspaceFolder . uri . fsPath ] , [ workspaceFolder ] , true ) )
479
+ // for some reason, uri created inline differ in subfields, so skipping them from assertion
480
+ . map ( ( { fileUri, ...r } ) => ( { ...r } ) )
481
+
482
+ result . sort ( ( l , r ) => l . relativeFilePath . localeCompare ( r . relativeFilePath ) )
483
+
484
+ // non-posix filePath check here is important.
485
+ assert . deepStrictEqual (
486
+ [
487
+ {
488
+ workspaceFolder,
489
+ relativeFilePath : path . join ( 'src' , 'folder2' , 'a.js' ) ,
490
+ fileSizeBytes : 12 ,
491
+ } ,
492
+ {
493
+ workspaceFolder,
494
+ relativeFilePath : path . join ( 'src' , 'folder2' , 'b.cs' ) ,
495
+ fileSizeBytes : 12 ,
496
+ } ,
497
+ ] satisfies typeof result ,
498
+ result
499
+ )
500
+ } )
501
+ } )
0 commit comments