@@ -9,6 +9,7 @@ describe('GitFacade', () => {
99 let facade : GitFacade
1010 let git : SimpleGit
1111 let repoDirectory : string
12+ let mainBranch : string
1213
1314 const configureGit = async ( ) => {
1415 const configs = {
@@ -34,25 +35,26 @@ describe('GitFacade', () => {
3435 beforeEach ( async ( ) => {
3536 repoDirectory = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'temp-repo-' ) )
3637 git = simpleGit ( repoDirectory )
37- await git . init ( [ '-b' , 'main' ] )
38+ await git . init ( )
3839 await configureGit ( )
3940 await createCommit ( 'lorem\n\n' , 'subject 1' )
4041 await createCommit ( 'lorem\n\n\n\nipsum\n\n' , 'subject 2' )
4142 await createCommit ( 'lorem\n\n\n\nipsum\n\n\n\ndolor' , 'subject 3\n\nbody test' )
4243 facade = new GitFacade ( )
4344 facade . updateWorkingDirectory ( repoDirectory )
45+ mainBranch = await facade . getMainBranch ( )
4446 } )
4547
4648 it ( 'happy path' , async ( ) => {
4749 const FIXABLE_COMMIT_INDEX = 1
48- const commitsBefore = await facade . getMainBranchCommits ( 'main' )
50+ const commitsBefore = await facade . getMainBranchCommits ( mainBranch )
4951 const fixableCommit = commitsBefore [ FIXABLE_COMMIT_INDEX ]
5052 await modifyFileAndStageChanges ( 'lorem\n\n\n\nfoobar\n\n' )
5153 await facade . commitFixup ( fixableCommit . hash )
5254 const isMergeConflict = await facade . rebaseFixupCommit ( fixableCommit . hash )
5355 expect ( isMergeConflict ) . toBe ( false )
5456 const fixedCommit = await facade . getLatestFixedCommit ( )
55- const commitsAfter = await facade . getMainBranchCommits ( 'main' )
57+ const commitsAfter = await facade . getMainBranchCommits ( mainBranch )
5658 expect ( commitsAfter [ FIXABLE_COMMIT_INDEX ] . hash ) . toEqual ( fixedCommit . hash )
5759 const fixedCommitDiff = await git . raw ( [ 'diff' , '-U0' , `${ fixedCommit . hash } ~` , `${ fixedCommit . hash } ` ] )
5860 expect ( fixedCommitDiff ) . toContain ( '+\n+\n+foobar\n+\n' )
@@ -61,19 +63,19 @@ describe('GitFacade', () => {
6163 } )
6264
6365 it ( 'getMainBranchCommits()' , async ( ) => {
64- const commits = await facade . getMainBranchCommits ( 'main' )
66+ const commits = await facade . getMainBranchCommits ( mainBranch )
6567 expect ( commits ) . toHaveLength ( 3 )
6668 const expectedLength = ( await git . raw ( [ 'rev-parse' , '--short' , 'HEAD' ] ) ) . trim ( ) . length
6769 expect ( commits . map ( ( c ) => c . hash . length ) ) . toEqual ( [ expectedLength , expectedLength , expectedLength ] )
6870 expect ( commits . map ( ( c ) => c . subject ) ) . toEqual ( [ 'subject 3' , 'subject 2' , 'subject 1' ] )
6971 } )
7072
7173 it ( 'getFeatureBranchCommits()' , async ( ) => {
72- const branchName = `feature-${ Date . now ( ) } `
73- await git . checkoutLocalBranch ( branchName )
74- expect ( await facade . getFeatureBranchCommits ( branchName , 'main' ) ) . toHaveLength ( 0 )
74+ const featureBranch = `feature-${ Date . now ( ) } `
75+ await git . checkoutLocalBranch ( featureBranch )
76+ expect ( await facade . getFeatureBranchCommits ( featureBranch , mainBranch ) ) . toHaveLength ( 0 )
7577 await createCommit ( 'foo' , 'bar' )
76- expect ( await facade . getFeatureBranchCommits ( branchName , 'main' ) ) . toHaveLength ( 1 )
78+ expect ( await facade . getFeatureBranchCommits ( featureBranch , mainBranch ) ) . toHaveLength ( 1 )
7779 } )
7880
7981 it ( 'getStagedFiles()' , async ( ) => {
0 commit comments