Skip to content
Snippets Groups Projects
Select Git revision
  • 53ca91301f6a36c0c87e7d6b06b1bd8c9ec1b283
  • main default protected
  • next
  • revert-31645-feat/rename-gradle-wrapper-validation-action
  • renovate/main-redis-5.x
  • fix/36615b-branch-reuse-no-cache
  • chore/punycode
  • fix/36615-branch-reuse-bug
  • refactor/pin-new-value
  • feat/36219--git-x509-signing
  • feat/structured-logger
  • hotfix/39.264.1
  • feat/skip-dangling
  • gh-readonly-queue/next/pr-36034-7a061c4ca1024a19e2c295d773d9642625d1c2be
  • hotfix/39.238.3
  • refactor/gitlab-auto-approve
  • feat/template-strings
  • gh-readonly-queue/next/pr-35654-137d934242c784e0c45d4b957362214f0eade1d7
  • fix/32307-global-extends-merging
  • fix/32307-global-extends-repositories
  • gh-readonly-queue/next/pr-35009-046ebf7cb84ab859f7fefceb5fa53a54ce9736f8
  • 41.34.1
  • 41.34.0
  • 41.33.0
  • 41.32.3
  • 41.32.2
  • 41.32.1
  • 41.32.0
  • 41.31.1
  • 41.31.0
  • 41.30.5
  • 41.30.4
  • 41.30.3
  • 41.30.2
  • 41.30.1
  • 41.30.0
  • 41.29.1
  • 41.29.0
  • 41.28.2
  • 41.28.1
  • 41.28.0
41 results

write.spec.ts

Blame
  • automerge.spec.ts 2.70 KiB
    import { defaultConfig, git, platform } from '../../../test/util';
    import { RenovateConfig } from '../../config';
    import { BranchStatus } from '../../types';
    import { tryBranchAutomerge } from './automerge';
    
    jest.mock('../../util/git');
    
    describe('workers/branch/automerge', () => {
      describe('tryBranchAutomerge', () => {
        let config: RenovateConfig;
        beforeEach(() => {
          config = {
            ...defaultConfig,
          };
        });
        it('returns false if not configured for automerge', async () => {
          config.automerge = false;
          expect(await tryBranchAutomerge(config)).toBe('no automerge');
        });
        it('returns false if automergType is pr', async () => {
          config.automerge = true;
          config.automergeType = 'pr';
          expect(await tryBranchAutomerge(config)).toBe('no automerge');
        });
        it('returns false if branch status is not success', async () => {
          config.automerge = true;
          config.automergeType = 'branch';
          platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.yellow);
          expect(await tryBranchAutomerge(config)).toBe('no automerge');
        });
        it('returns branch status error if branch status is failure', async () => {
          config.automerge = true;
          config.automergeType = 'branch';
          platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.red);
          expect(await tryBranchAutomerge(config)).toBe('branch status error');
        });
        it('returns false if PR exists', async () => {
          platform.getBranchPr.mockResolvedValueOnce({} as never);
          config.automerge = true;
          config.automergeType = 'branch';
          platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green);
          expect(await tryBranchAutomerge(config)).toBe(
            'automerge aborted - PR exists'
          );
        });
        it('returns false if automerge fails', async () => {
          config.automerge = true;
          config.automergeType = 'branch';
          platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green);
          git.mergeBranch.mockImplementationOnce(() => {
            throw new Error('merge error');
          });
          expect(await tryBranchAutomerge(config)).toBe('failed');
        });
        it('returns true if automerge succeeds', async () => {
          config.automerge = true;
          config.automergeType = 'branch';
          platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green);
          expect(await tryBranchAutomerge(config)).toBe('automerged');
        });
        it('returns true if automerge succeeds (dry-run)', async () => {
          config.automerge = true;
          config.automergeType = 'branch';
          config.dryRun = true;
          platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green);
          expect(await tryBranchAutomerge(config)).toBe('automerged');
        });
      });
    });