renovate/lib/workers/branch/commit.spec.ts
2021-03-02 21:44:55 +01:00

49 lines
1.6 KiB
TypeScript

import { defaultConfig, git, partial } from '../../../test/util';
import { setAdminConfig } from '../../config/admin';
import type { BranchConfig } from '../types';
import { commitFilesToBranch } from './commit';
jest.mock('../../util/git');
describe('workers/branch/automerge', () => {
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('abc123');
setAdminConfig();
});
it('handles empty files', async () => {
await commitFilesToBranch(config);
expect(git.commitFiles).toHaveBeenCalledTimes(0);
});
it('commits files', async () => {
config.updatedPackageFiles.push({
name: 'package.json',
contents: 'some contents',
});
await commitFilesToBranch(config);
expect(git.commitFiles).toHaveBeenCalledTimes(1);
expect(git.commitFiles.mock.calls).toMatchSnapshot();
});
it('dry runs', async () => {
setAdminConfig({ dryRun: true });
config.updatedPackageFiles.push({
name: 'package.json',
contents: 'some contents',
});
await commitFilesToBranch(config);
expect(git.commitFiles).toHaveBeenCalledTimes(0);
});
});
});