|
| 1 | +import { createTestContext, like, setUpFilesAdded, setUpInit, SimpleGitTestContext } from '@simple-git/test-utils'; |
| 2 | + |
| 3 | +describe('branch-show-current', () => { |
| 4 | + let context: SimpleGitTestContext; |
| 5 | + |
| 6 | + const expectedBranchSummary = (commit = '', label = '') => like({ |
| 7 | + all: ['my-new-branch'], |
| 8 | + current: 'my-new-branch', |
| 9 | + branches: { |
| 10 | + 'my-new-branch': { |
| 11 | + name: 'my-new-branch', |
| 12 | + commit, |
| 13 | + label, |
| 14 | + current: true, |
| 15 | + linkedWorkTree: false, |
| 16 | + }, |
| 17 | + }, |
| 18 | + }); |
| 19 | + |
| 20 | + |
| 21 | + beforeEach(async () => (context = await createTestContext())); |
| 22 | + beforeEach(async () => { |
| 23 | + await setUpInit(context); |
| 24 | + await context.git.raw('checkout', '-b', 'my-new-branch'); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should be able to show you the current on an empty repo', async () => { |
| 28 | + expect(await context.git.branch(['--show-current'])) |
| 29 | + .toEqual(expectedBranchSummary()); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should be able to show you the current on an regular repo', async () => { |
| 33 | + await setUpFilesAdded(context, ['some-file'], '.', 'Initial Commit'); |
| 34 | + |
| 35 | + expect(await context.git.branch(['--show-current'])) |
| 36 | + .toEqual(expectedBranchSummary()); |
| 37 | + |
| 38 | + const branch = await context.git.branch(); |
| 39 | + expect(branch).toEqual(expectedBranchSummary( |
| 40 | + expect.stringMatching(/^.{7}$/), |
| 41 | + 'Initial Commit', |
| 42 | + )); |
| 43 | + }); |
| 44 | +}); |
0 commit comments