renovate/test/workers/branch/commit.spec.ts

49 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-12-09 11:42:55 +00:00
import {
commitFilesToBranch,
CommitConfig,
} from '../../../lib/workers/branch/commit';
import { defaultConfig, platform } from '../../util';
import { RenovateConfig } from '../../../lib/config';
2019-07-17 08:14:56 +00:00
describe('workers/branch/automerge', () => {
describe('commitFilesToBranch', () => {
2019-12-09 11:42:55 +00:00
let config: RenovateConfig & CommitConfig;
beforeEach(() => {
config = {
...defaultConfig,
branchName: 'renovate/some-branch',
commitMessage: 'some commit message',
semanticCommits: false,
semanticCommitType: 'a',
semanticCommitScope: 'b',
updatedPackageFiles: [],
updatedArtifacts: [],
};
jest.resetAllMocks();
platform.commitFilesToBranch.mockResolvedValueOnce('abc123');
});
it('handles empty files', async () => {
await commitFilesToBranch(config);
expect(platform.commitFilesToBranch).toHaveBeenCalledTimes(0);
});
it('commits files', async () => {
config.updatedPackageFiles.push({
name: 'package.json',
contents: 'some contents',
});
await commitFilesToBranch(config);
expect(platform.commitFilesToBranch).toHaveBeenCalledTimes(1);
expect(platform.commitFilesToBranch.mock.calls).toMatchSnapshot();
});
it('dry runs', async () => {
config.dryRun = true;
config.updatedPackageFiles.push({
name: 'package.json',
contents: 'some contents',
});
await commitFilesToBranch(config);
expect(platform.commitFilesToBranch).toHaveBeenCalledTimes(0);
});
});
});