-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
commit.spec.ts
63 lines (61 loc) · 2.05 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
import { defaultConfig, git, partial, platform } from '../../../test/util';
import { GlobalConfig } from '../../config/global';
import type { BranchConfig } from '../types';
import { commitFilesToBranch } from './commit';
jest.mock('../../util/git');
describe('workers/branch/commit', () => {
describe('commitFilesToBranch', () => {
let config: BranchConfig;
beforeEach(() => {
config = partial<BranchConfig>({
...defaultConfig,
branchName: 'renovate/some-branch',
commitMessage: 'some commit message',
semanticCommits: 'disabled',
semanticCommitType: 'a',
semanticCommitScope: 'b',
updatedPackageFiles: [],
updatedArtifacts: [],
});
jest.resetAllMocks();
git.commitFiles.mockResolvedValueOnce('123test');
platform.commitFiles = jest.fn();
GlobalConfig.reset();
});
it('handles empty files', async () => {
await commitFilesToBranch(config);
expect(git.commitFiles).toHaveBeenCalledTimes(0);
});
it('commits files', async () => {
config.updatedPackageFiles.push({
type: 'addition',
path: 'package.json',
contents: 'some contents',
});
await commitFilesToBranch(config);
expect(git.commitFiles).toHaveBeenCalledTimes(1);
expect(git.commitFiles.mock.calls).toMatchSnapshot();
});
it('commits via platform', async () => {
config.updatedPackageFiles.push({
type: 'addition',
path: 'package.json',
contents: 'some contents',
});
config.platformCommit = true;
await commitFilesToBranch(config);
expect(platform.commitFiles).toHaveBeenCalledTimes(1);
expect(platform.commitFiles.mock.calls).toMatchSnapshot();
});
it('dry runs', async () => {
GlobalConfig.set({ dryRun: true });
config.updatedPackageFiles.push({
type: 'addition',
path: 'package.json',
contents: 'some contents',
});
await commitFilesToBranch(config);
expect(git.commitFiles).toHaveBeenCalledTimes(0);
});
});
});