/
gitInfo.test.js
42 lines (38 loc) · 1.4 KB
/
gitInfo.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { getCommitAndBranch } from '../git/getCommitAndBranch';
import { getBaselineCommits, getSlug, getVersion } from '../git/git';
import { setGitInfo } from './gitInfo';
jest.mock('../git/getCommitAndBranch');
jest.mock('../git/git');
const log = { debug: jest.fn() };
describe('setGitInfo', () => {
it('sets the git info on context', async () => {
getCommitAndBranch.mockResolvedValue({ commit: '123asdf', branch: 'something' });
getBaselineCommits.mockResolvedValue(['asd2344']);
getVersion.mockResolvedValue('Git v1.0.0');
getSlug.mockResolvedValue('user/repo');
const ctx = { log, options: {} };
await setGitInfo(ctx, {});
expect(ctx.git).toMatchObject({
commit: '123asdf',
branch: 'something',
baselineCommits: ['asd2344'],
version: 'Git v1.0.0',
slug: 'user/repo',
});
});
it('supports overriding the owner name in the slug', async () => {
getCommitAndBranch.mockResolvedValue({ commit: '123asdf', branch: 'something' });
getBaselineCommits.mockResolvedValue(['asd2344']);
getVersion.mockResolvedValue('Git v1.0.0');
getSlug.mockResolvedValue('user/repo');
const ctx = { log, options: { ownerName: 'org' } };
await setGitInfo(ctx, {});
expect(ctx.git).toMatchObject({
commit: '123asdf',
branch: 'something',
baselineCommits: ['asd2344'],
version: 'Git v1.0.0',
slug: 'org/repo',
});
});
});