| 1 | import { execFileSync } from 'node:child_process'; |
| 2 | import { mkdirSync, mkdtempSync |
| 3 | import { tmpdir } |
| 4 | import path from 'node:path |
| 5 | import { afterEach, beforeEach |
| 6 | |
| 7 | import { listCommits, readCommit |
| 8 | |
| 9 | describe('listCommits', () |
| 10 | let root: |
| 11 | let gitDir: |
| 12 | |
| 13 | beforeEach(() => |
| 14 | root = mkdtempSync( |
| 15 | gitDir = path. |
| 16 | const env = |
| 17 | delete env.GIT_DIR; |
| 18 | const git = |
| 19 | execFileSync('git', |
| 20 | |
| 21 | execFileSync('git', |
| 22 | git('config', |
| 23 | git('config', |
| 24 | mkdirSync(path.join |
| 25 | |
| 26 | writeFileSync(path.join |
| 27 | git('add', |
| 28 | git('commit', |
| 29 | |
| 30 | writeFileSync(path.join |
| 31 | git('add', |
| 32 | git('commit', |
| 33 | |
| 34 | writeFileSync(path.join |
| 35 | git('add', |
| 36 | git('commit', |
| 37 | }); |
| 38 | |
| 39 | afterEach(() => |
| 40 | |
| 41 | it('lists newest first', |
| 42 | const { commits, |
| 43 | gitDir, |
| 44 | ref: 'main', |
| 45 | limit: 10, |
| 46 | }); |
| 47 | |
| 48 | expect(commits.map |
| 49 | expect(commits[1] |
| 50 | expect(commits[0] |
| 51 | expect(nextCursor).toBeNull |
| 52 | }); |
| 53 | |
| 54 | it('pages with the cursor', |
| 55 | const first = |
| 56 | expect(first.commits |
| 57 | |
| 58 | const second = |
| 59 | gitDir, |
| 60 | ref: 'main', |
| 61 | limit: 2, |
| 62 | cursor: first.nextCursor |
| 63 | }); |
| 64 | expect(second.commits |
| 65 | expect(second.nextCursor |
| 66 | }); |
| 67 | |
| 68 | it('narrows to a path', |
| 69 | const { commits |
| 70 | gitDir, |
| 71 | ref: 'main', |
| 72 | path: 'src', |
| 73 | limit: 10, |
| 74 | }); |
| 75 | |
| 76 | expect(commits.map |
| 77 | }); |
| 78 | |
| 79 | it('reads one commit with its changed paths', |
| 80 | const { commits |
| 81 | const commit = |
| 82 | |
| 83 | expect(commit?.subject |
| 84 | expect(commit?.files |
| 85 | }); |
| 86 | |
| 87 | it('returns null for an unknown sha', |
| 88 | expect(await readCommit |
| 89 | }); |
| 90 | }); |