forked from renovatebot/renovate
/
commit.spec.ts
72 lines (67 loc) · 2.09 KB
/
commit.spec.ts
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { scm } from '../../../../../test/util';
import { GlobalConfig } from '../../../../config/global';
import type { BranchConfig } from '../../../types';
import { commitFilesToBranch } from './commit';
describe('workers/repository/update/branch/commit', () => {
describe('commitFilesToBranch', () => {
let config: BranchConfig;
beforeEach(() => {
config = {
baseBranch: 'base-branch',
manager: 'some-manager',
branchName: 'renovate/some-branch',
commitMessage: 'some commit message',
semanticCommits: 'disabled',
semanticCommitType: 'a',
semanticCommitScope: 'b',
updatedPackageFiles: [],
updatedArtifacts: [],
upgrades: [],
} satisfies BranchConfig;
jest.resetAllMocks();
scm.commitAndPush.mockResolvedValueOnce('123test');
GlobalConfig.reset();
});
it('handles empty files', async () => {
await commitFilesToBranch(config);
expect(scm.commitAndPush).toHaveBeenCalledTimes(0);
});
it('commits files', async () => {
config.updatedPackageFiles?.push({
type: 'addition',
path: 'package.json',
contents: 'some contents',
});
await commitFilesToBranch(config);
expect(scm.commitAndPush).toHaveBeenCalledTimes(1);
expect(scm.commitAndPush.mock.calls).toEqual([
[
{
baseBranch: 'base-branch',
branchName: 'renovate/some-branch',
files: [
{
contents: 'some contents',
path: 'package.json',
type: 'addition',
},
],
force: false,
message: 'some commit message',
platformCommit: false,
},
],
]);
});
it('dry runs', async () => {
GlobalConfig.set({ dryRun: 'full' });
config.updatedPackageFiles?.push({
type: 'addition',
path: 'package.json',
contents: 'some contents',
});
await commitFilesToBranch(config);
expect(scm.commitAndPush).toHaveBeenCalledTimes(0);
});
});
});