@@ -41,6 +41,20 @@ describe("changedFiles", () => {
4141 vi . mocked ( simpleGit . simpleGit ( ) . diff ) . mockResolvedValue ( files . join ( "\n" ) ) ;
4242
4343 await expect ( getChangedFiles ( options ) ) . resolves . toEqual ( files ) ;
44+ expect ( simpleGit . simpleGit ( ) . diff ) . toHaveBeenCalledWith ( [ "--name-only" , "HEAD^" , "HEAD" ] ) ;
45+
46+ const specFiles = files . filter ( ( f ) => f . startsWith ( "specification" ) ) ;
47+ vi . mocked ( simpleGit . simpleGit ( ) . diff ) . mockResolvedValue ( specFiles . join ( "\n" ) ) ;
48+ await expect ( getChangedFiles ( { ...options , paths : [ "specification" ] } ) ) . resolves . toEqual (
49+ specFiles ,
50+ ) ;
51+ expect ( simpleGit . simpleGit ( ) . diff ) . toHaveBeenCalledWith ( [
52+ "--name-only" ,
53+ "HEAD^" ,
54+ "HEAD" ,
55+ "--" ,
56+ "specification" ,
57+ ] ) ;
4458 } ) ;
4559
4660 const files = [
@@ -174,6 +188,7 @@ describe("changedFiles", () => {
174188 "should categorize files correctly with all types of changes (%o)" ,
175189 async ( options ) => {
176190 const gitOutput = [
191+ "M\t.github/src/changed-files.js" ,
177192 "A\tspecification/new-service/readme.md" ,
178193 "M\tspecification/existing-service/main.tsp" ,
179194 "D\tspecification/old-service/contoso.json" ,
@@ -183,7 +198,31 @@ describe("changedFiles", () => {
183198 ] . join ( "\n" ) ;
184199
185200 vi . mocked ( simpleGit . simpleGit ( ) . diff ) . mockResolvedValue ( gitOutput ) ;
186- const result = await getChangedFilesStatuses ( options ) ;
201+ let result = await getChangedFilesStatuses ( options ) ;
202+ expect ( result ) . toEqual ( {
203+ additions : [ "specification/new-service/readme.md" , "specification/service/derived.json" ] ,
204+ modifications : [
205+ ".github/src/changed-files.js" ,
206+ "specification/existing-service/main.tsp" ,
207+ "specification/service/type-changed.json" ,
208+ ] ,
209+ deletions : [ "specification/old-service/contoso.json" ] ,
210+ renames : [
211+ {
212+ from : "specification/service/old-name.json" ,
213+ to : "specification/service/new-name.json" ,
214+ } ,
215+ ] ,
216+ total : 7 ,
217+ } ) ;
218+ expect ( simpleGit . simpleGit ( ) . diff ) . toHaveBeenCalledWith ( [ "--name-status" , "HEAD^" , "HEAD" ] ) ;
219+
220+ const specGitOutput = gitOutput
221+ . split ( "\n" )
222+ . filter ( ( f ) => f . includes ( "specification/" ) )
223+ . join ( "\n" ) ;
224+ vi . mocked ( simpleGit . simpleGit ( ) . diff ) . mockResolvedValue ( specGitOutput ) ;
225+ result = await getChangedFilesStatuses ( { ...options , paths : [ "specification" ] } ) ;
187226 expect ( result ) . toEqual ( {
188227 additions : [ "specification/new-service/readme.md" , "specification/service/derived.json" ] ,
189228 modifications : [
@@ -199,6 +238,13 @@ describe("changedFiles", () => {
199238 ] ,
200239 total : 6 ,
201240 } ) ;
241+ expect ( simpleGit . simpleGit ( ) . diff ) . toHaveBeenCalledWith ( [
242+ "--name-status" ,
243+ "HEAD^" ,
244+ "HEAD" ,
245+ "--" ,
246+ "specification" ,
247+ ] ) ;
202248 } ,
203249 ) ;
204250
0 commit comments