@@ -770,18 +770,19 @@ describe("getGitHistory", () => {
770770
771771 const history = await getGitHistory ( testDir , 5 ) ;
772772
773- expect ( history ) . toHaveLength ( 2 ) ;
774- expect ( history [ 0 ] ) . toEqual (
773+ expect ( history . hasMore ) . toBe ( false ) ;
774+ expect ( history . entries ) . toHaveLength ( 2 ) ;
775+ expect ( history . entries [ 0 ] ) . toEqual (
775776 expect . objectContaining ( {
776777 subject : "second commit" ,
777778 authorName : "Test" ,
778779 } )
779780 ) ;
780- expect ( history [ 0 ] ?. sha ) . toHaveLength ( 40 ) ;
781- expect ( history [ 0 ] ?. shortSha ) . toHaveLength ( 7 ) ;
782- expect ( history [ 0 ] ?. authoredAt ) . toBeTypeOf ( "number" ) ;
783- expect ( history [ 0 ] ! . authoredAt ) . toBeGreaterThanOrEqual ( history [ 1 ] ! . authoredAt ) ;
784- expect ( history [ 1 ] ) . toEqual (
781+ expect ( history . entries [ 0 ] ?. sha ) . toHaveLength ( 40 ) ;
782+ expect ( history . entries [ 0 ] ?. shortSha ) . toHaveLength ( 7 ) ;
783+ expect ( history . entries [ 0 ] ?. authoredAt ) . toBeTypeOf ( "number" ) ;
784+ expect ( history . entries [ 0 ] ! . authoredAt ) . toBeGreaterThanOrEqual ( history . entries [ 1 ] ! . authoredAt ) ;
785+ expect ( history . entries [ 1 ] ) . toEqual (
785786 expect . objectContaining ( {
786787 subject : "first commit" ,
787788 authorName : "Test" ,
@@ -795,7 +796,45 @@ describe("getGitHistory", () => {
795796 const testDir = await mkdtemp ( join ( tmpdir ( ) , "git-history-empty-" ) ) ;
796797 await execFileAsync ( "git" , [ "init" ] , { cwd : testDir } ) ;
797798
798- await expect ( getGitHistory ( testDir , 5 ) ) . resolves . toEqual ( [ ] ) ;
799+ await expect ( getGitHistory ( testDir , 5 ) ) . resolves . toEqual ( {
800+ entries : [ ] ,
801+ hasMore : false ,
802+ } ) ;
803+
804+ await rm ( testDir , { recursive : true , force : true } ) ;
805+ } ) ;
806+
807+ it ( "returns paged commits after a cursor without duplicating the cursor" , async ( ) => {
808+ const testDir = await mkdtemp ( join ( tmpdir ( ) , "git-history-paged-" ) ) ;
809+ await execFileAsync ( "git" , [ "init" ] , { cwd : testDir } ) ;
810+ await execFileAsync ( "git" , [ "config" , "user.name" , "Test" ] , { cwd : testDir } ) ;
811+ await execFileAsync ( "git" , [ "config" , "user.email" , "test@example.com" ] , { cwd : testDir } ) ;
812+
813+ for ( const subject of [ "first commit" , "second commit" , "third commit" , "fourth commit" ] ) {
814+ await writeFile ( join ( testDir , "file.txt" ) , `${ subject } \n` ) ;
815+ await execFileAsync ( "git" , [ "add" , "." ] , { cwd : testDir } ) ;
816+ await execFileAsync ( "git" , [ "commit" , "-m" , subject ] , { cwd : testDir } ) ;
817+ }
818+
819+ const firstPage = await getGitHistory ( testDir , { limit : 2 } ) ;
820+
821+ expect ( firstPage . hasMore ) . toBe ( true ) ;
822+ expect ( firstPage . entries . map ( ( entry ) => entry . subject ) ) . toEqual ( [
823+ "fourth commit" ,
824+ "third commit" ,
825+ ] ) ;
826+
827+ const secondPage = await getGitHistory ( testDir , {
828+ limit : 2 ,
829+ afterSha : firstPage . entries [ 1 ] ! . sha ,
830+ } ) ;
831+
832+ expect ( secondPage . hasMore ) . toBe ( false ) ;
833+ expect ( secondPage . entries . map ( ( entry ) => entry . subject ) ) . toEqual ( [
834+ "second commit" ,
835+ "first commit" ,
836+ ] ) ;
837+ expect ( secondPage . entries . map ( ( entry ) => entry . sha ) ) . not . toContain ( firstPage . entries [ 1 ] ! . sha ) ;
799838
800839 await rm ( testDir , { recursive : true , force : true } ) ;
801840 } ) ;
0 commit comments