@@ -13,7 +13,7 @@ describe('findNonSourceAffectedFiles', () => {
1313
1414 it ( 'should return relevant files' , ( ) => {
1515 const cwd = '/project' ;
16- const changedFilePath = '/project/src/file.ts' ;
16+ const changedFilePaths = [ '/project/src/file.ts' ] ;
1717 const excludeFolderPaths = [ 'node_modules' , 'dist' , '.git' ] ;
1818
1919 ( fastFindInFiles as jest . Mock ) . mockReturnValue ( [
@@ -26,14 +26,50 @@ describe('findNonSourceAffectedFiles', () => {
2626
2727 const result = findNonSourceAffectedFiles (
2828 cwd ,
29- changedFilePath ,
29+ changedFilePaths ,
3030 excludeFolderPaths
3131 ) ;
3232
3333 expect ( result ) . toEqual ( [ { filePath : 'src/file.ts' , changedLines : [ 1 ] } ] ) ;
3434 expect ( fastFindInFiles ) . toHaveBeenCalledWith ( {
3535 directory : cwd ,
36- needle : path . basename ( changedFilePath ) ,
36+ needle : new RegExp (
37+ changedFilePaths
38+ . map ( ( changedFilePath ) => path . basename ( changedFilePath ) )
39+ . join ( '|' )
40+ . replaceAll ( '.' , '\\.' )
41+ ) ,
42+ excludeFolderPaths : excludeFolderPaths . map ( ( folder ) =>
43+ path . join ( cwd , folder )
44+ ) ,
45+ } ) ;
46+ } ) ;
47+
48+ it ( 'should aggregate changedFilePaths to regExp needle' , ( ) => {
49+ const cwd = '/project' ;
50+ const changedFilePaths = [ '/project/src/file.ts' , '/project/src/file2.ts' ] ;
51+ const excludeFolderPaths = [ 'node_modules' , 'dist' , '.git' ] ;
52+ ( fastFindInFiles as jest . Mock ) . mockReturnValue ( [
53+ {
54+ filePath : '/project/src/file.ts' ,
55+ queryHits : [ { lineNumber : 1 , line : `"file.ts"` } ] ,
56+ } ,
57+ ] ) ;
58+ ( existsSync as jest . Mock ) . mockReturnValue ( true ) ;
59+ const result = findNonSourceAffectedFiles (
60+ cwd ,
61+ changedFilePaths ,
62+ excludeFolderPaths
63+ ) ;
64+ expect ( result ) . toEqual ( [ { filePath : 'src/file.ts' , changedLines : [ 1 ] } ] ) ;
65+ expect ( fastFindInFiles ) . toHaveBeenCalledWith ( {
66+ directory : cwd ,
67+ needle : new RegExp (
68+ changedFilePaths
69+ . map ( ( changedFilePath ) => path . basename ( changedFilePath ) )
70+ . join ( '|' )
71+ . replaceAll ( '.' , '\\.' )
72+ ) ,
3773 excludeFolderPaths : excludeFolderPaths . map ( ( folder ) =>
3874 path . join ( cwd , folder )
3975 ) ,
@@ -42,22 +78,27 @@ describe('findNonSourceAffectedFiles', () => {
4278
4379 it ( 'should return empty array if no relevant files found' , ( ) => {
4480 const cwd = '/project' ;
45- const changedFilePath = '/project/src/file.ts' ;
81+ const changedFilePaths = [ '/project/src/file.ts' ] ;
4682 const excludeFolderPaths = [ 'node_modules' , 'dist' , '.git' ] ;
4783
4884 ( fastFindInFiles as jest . Mock ) . mockReturnValue ( [ ] ) ;
4985 ( existsSync as jest . Mock ) . mockReturnValue ( true ) ;
5086
5187 const result = findNonSourceAffectedFiles (
5288 cwd ,
53- changedFilePath ,
89+ changedFilePaths ,
5490 excludeFolderPaths
5591 ) ;
5692
5793 expect ( result ) . toEqual ( [ ] ) ;
5894 expect ( fastFindInFiles ) . toHaveBeenCalledWith ( {
5995 directory : cwd ,
60- needle : path . basename ( changedFilePath ) ,
96+ needle : new RegExp (
97+ changedFilePaths
98+ . map ( ( changedFilePath ) => path . basename ( changedFilePath ) )
99+ . join ( '|' )
100+ . replaceAll ( '.' , '\\.' )
101+ ) ,
61102 excludeFolderPaths : excludeFolderPaths . map ( ( folder ) =>
62103 path . join ( cwd , folder )
63104 ) ,
@@ -66,7 +107,7 @@ describe('findNonSourceAffectedFiles', () => {
66107
67108 it ( "should still work even if found file didn't have a match" , ( ) => {
68109 const cwd = '/project' ;
69- const changedFilePath = '/project/src/file.ts' ;
110+ const changedFilePaths = [ '/project/src/file.ts' ] ;
70111 const excludeFolderPaths = [ 'node_modules' , 'dist' , '.git' ] ;
71112
72113 ( fastFindInFiles as jest . Mock ) . mockReturnValue ( [
@@ -79,14 +120,19 @@ describe('findNonSourceAffectedFiles', () => {
79120
80121 const result = findNonSourceAffectedFiles (
81122 cwd ,
82- changedFilePath ,
123+ changedFilePaths ,
83124 excludeFolderPaths
84125 ) ;
85126
86127 expect ( result ) . toEqual ( [ ] ) ;
87128 expect ( fastFindInFiles ) . toHaveBeenCalledWith ( {
88129 directory : cwd ,
89- needle : path . basename ( changedFilePath ) ,
130+ needle : new RegExp (
131+ changedFilePaths
132+ . map ( ( changedFilePath ) => path . basename ( changedFilePath ) )
133+ . join ( '|' )
134+ . replaceAll ( '.' , '\\.' )
135+ ) ,
90136 excludeFolderPaths : excludeFolderPaths . map ( ( folder ) =>
91137 path . join ( cwd , folder )
92138 ) ,
0 commit comments